The basics of the python learning process of Caiji (1)


Preface

About Python's basic writing format and indentation and comments


One, indentation:

Indentation in Python is the soul. As we all know, a pair of "{}" symbols are used to indicate the level of code blocks in JAVA, while Python uses different indentations to indicate different code block levels, such as:

sc=input("你多大了?")
if sc=="成年":
    print("成年了 ")
else:
    print("未成年")
print ("问答结束!")

It can be clearly seen that different indentations indicate different levels. The top code block has the largest level. The more indentation, the smaller the code block level. The smaller the indentation, the larger the code block level.

2. Notes:

1. Single line comment:

Single-line comments in Python generally use the "#" sign, such as:

# print("Hello,Word")

2. Multi-line comments:

Multi-line comments can use multiple "#" signs:

# sc=input("你多大了?")
# if sc=="成年":
#     print("成年了 ")
# else:
#     print("未成年")
# print ("问答结束!")

Tip: The "#" annotation method shortcut key in PyChram is "CTRL+/"

Of course, you can also use the '' 'symbol:

'''sc=input("你多大了?")
if sc=="成年":
    print("成年了 ")
else:
    print("未成年")
print ("问答结束!")'''
print("好好学习")

Or "" "symbol:

"""sc=input("你多大了?")
if sc=="成年":
    print("成年了 ")
else:
    print("未成年")
print ("问答结束!")"""
print("好好学习")

Note: '' 'comment method and "" "comment method need to be marked at the beginning and end of the comment code block to indicate the comment range

Three, writing format:

1.Identifier (variable name) naming rules:

(1). A character must be a letter or underscore in the alphabet.

(2). The other parts of the identifier are composed of letters, numbers and underscores.

(3). Identifiers have requirements for upper and lower case, so they must be distinguished.

(4). Identifiers cannot be keywords in Python.

(5). Chinese and non-ASCII codes can be used as identifiers, but not recommended

2. Keywords:

There are many keywords in Python, such as:

Represents the data type: such as int str float, etc.

Represents boole type: such as True False

Special sentence keywords: such as if elif else for while, etc.

Keywords of function class: such as def .keys() .values() etc.

There are still many keywords that cannot be used, so I won't go into details.

to sum up

Indentation:

Indentation is the soul in Python. Different indentations represent different code block levels. In the daily writing process, you must pay attention to the indentation of code blocks.

Notes:

Although there are many comment methods, they have the same uses. According to the habit, the biggest use of comments is to identify the use of each code block or statement. You usually need to write more comments in the writing process.

Identifiers and keywords:

One thing to remember is that identifiers must not be keywords, otherwise an error will be reported.

Okay, finally let us shout again Python game

(The above comes from the understanding of a little novice, don’t spray if you don’t like it)

Guess you like

Origin blog.csdn.net/weixin_45279175/article/details/112467794