1. Input method input()
Wait for the user to input data, and press Enter to get the data (name is the input string)
name=input('Please input your name:') print('Hi,',name)
Running the code effect:
2. The way of writing comments: # at the beginning
The statement ends with a colon: When the indented statement is regarded as a code block, it is not specified how many spaces the indentation is, but the convention is commonly called 4 spaces.
#Note:firse code demo #print absolute value of an integer: a=100 if a >=0: print(a) else: print(-a)
The output is:
3. Data type
Integer, such as 20, -100
Floating point numbers, such as 1.2323, use scientific notation for very large numbers, use e instead of 10, such as 1.23x10 9 is 1.23e9
Strings like 'abc', "hello world",
Escape, use \ to escape single and double quotes, \\ to escape \, \n newline, \t tab,
No escaping, r'\xxx\xxx' means '\xxx\xxx' without escaping
Multi-line, use '''xxxxxxx''' to represent multi-line content
print('''line1 line2 line3 '' )
The output is
Boolean value, only 2 values, True and False, pay attention to case, Python is case sensitive. He can use and, or, not for operations.
The null value, None, cannot be interpreted as 0, because 0 is meaningful and None is a special null value.
Constants, usually with all uppercase variable names to represent constants, such as the writing of π: PI=3.14159265359
There are also dictionaries, lists, and custom data types.
4. Variables
The variable name must be _
a combination of uppercase and lowercase English, numbers and, and cannot start with a number.
In Python, the equal sign =
is an assignment statement, which can assign any data type to a variable. The same variable can be assigned repeatedly, and it can be a variable of different types, such as
a = 123 # a is an integer print (a) a = ' ABC ' # a becomes a string print (a)
Also, there is another division //
, called floor division, where the division of two integers is still integers:
>>> 10 // 3 3