python—comments, output input (print, input), identifiers and keywords

note        

Comments refer to the suggestive content that explains the code functions in the code, which can enhance the readability of the code. The content of the comments will be ignored by the python interpreter and will not be reflected in the running results.

       In python, there are usually two types of comments, single-line comments and multi-line comments.

1. Single-line comments

       Single-line comments in python start with #, starting from the symbol # until the line break, and everything behind it is ignored by the python interpreter as the content of the comment.

       Single-line comments can be placed on the previous line of the code to be commented, or to the right of the code to be commented.

example:

# 第一种

# 要求输入整数
num = input("请输入一个整数:")


# 第二种

num = input("请输入一个整数:")  # 要求输入整数

2. Multi-line comments

Multi-line comments are usually used to add copyright information, function description and other information to python files, modules, classes or functions.

(1) Python multi-line comments use multiple # .

# 开发人员:administrator
# 开发时间:2003/07/15
# 文件名称:111.py
# 开发工具:pycharm

(2) Multi-line comments are marked with three single quotes ''' or three double quotes """

'''
这是多行注释,用三个单引号
这是多行注释,用三个单引号
这是多行注释,用三个单引号
'''

"""
这是多行注释,用三个双引号
这是多行注释,用三个双引号
这是多行注释,用三个双引号
"""

The difference between the two is that newlines are allowed inside the three single quotes, which preserves the format of the text.

Basic usage of print() function

1. The basic syntax format of the print() function is as follows:

print(输出内容)

 2. Wrap output and non-wrap output

In python, by default, a print() statement will automatically wrap after output. If you want to output multiple contents at a time without wrapping, you need to add end="" to the print() function, or you can output the content Use a comma, to separate and output.

Default: Use the print() function to achieve newline output

x = "a"
y = "b"
print(x)
print(y)

 Use the print() function to achieve non-wrapping output:

x = "a"
y = "b"
print(x, end=" ")
print(y)
print(x, y)

The sep parameter is used to indicate the output, which character is used to separate each value
print('hello', 'good', 'yes', 'hi', sep='+')  # 使用+号作为分隔符

 

 3. Convert the output value to a string

If you want to convert the value output by the print() function into a string, you can use the str() or repr() function to achieve

The str() function returns a human-readable representation

The repr() function produces an interpreter-readable representation

x = 10 * 3.25
y = 100 * 200
str = "x的值为:" + repr(x) + ", y的值为:" + str(y)
print(str)

 Basic usage of input() function

 Python provides the input() built-in function to read text from standard input, and the default standard input is the keyboard.

The basic syntax format of the input() function:

变量名 = input("<提示文本>")
password = input("请输入密码:")
print("你输入的密码是:", password)

 Identifiers and keywords

      Commonly used identifier naming rules in computer programs include small camel case, large camel case, Hungarian notation, and underscore.
Identifiers: variables, module names, function names, class names

As long as it is taken by yourself, it can be used as an identifier

Naming and specification of identifiers:

Rules: 1, number, letter, _, composition; cannot start with a number

           2. Strictly case-sensitive (in computer language, there are a total of 52 English letters)

           3. Cannot use keywords Keywords are words with special meaning in python language

                For example: if / for / while / try Specification:
small camel case nomenclature: the first letter of the first word is lowercase, and the first
                         letter of each word after that is capitalized userNameAndPassword

Big hump nomenclature: the first letter of each word is capitalized UserNameAndPassword

Link user_name_and_password with underscore

In python, variable, function and module names are connected by underscores, and
class names use big camel case

Guess you like

Origin blog.csdn.net/m0_69034993/article/details/127758329