1.1 Printout
# Print string (Chinese, English, numbers)
print('Hello,Word')
# Print numbers
print(123)
1.2 Three kinds of quotation marks for print
# Single quotes print string text
print('apostrophe')
# Double quotes can print text with single quotes in a string
print("Double quotes")
# Triple quotation marks can print out newline text
print('''Triple quotes''')
# You can use triple quotation marks to wrap, output the newline in the text as it is, not automatically wrap
print('''Triple quotation mark 1
Triple quotation mark 2
Triple quotation mark 3''')
# Escape character\n, can realize automatic line wrapping
print('Hello \n Word!')
3.1 Build a compilation environment
Python download: https://www.python.org/downloads/
3.2 Install editor
Python's own editor: IDLE
Third-party editors: vscode, pycharm
Variable: It can be a number, it can be any data type, it can be changed, it is not a constant layer; it is not recommended to use BIF in python.
Assignment: Add a data to the variable to increase the readability of the code.
a ='Assign a value to variable a'
Specification of variable names:
1 ) Cannot use Chinese, only English;
2 ) Can only be an underscore of alphanumeric values;
3 ) Cannot start with a number;
4 ) Cannot use BIF in Python (BIF refers to an internal function in Python) as a variable;
5 ) Try to describe the content of variables.
5.1 String
str() can convert other data types to strings
number ='60'print(str(number))The 60 printed here is a string type
5.2 Integer
int() can convert other data types to integers
number ='60'print(int(number))The 60 printed here is an integer type
5.3 Floating point number (number with decimal point) float()
number ='60'print(float(number))The result printed here is 60.0, the data type is floating point
a =80
b =89
c ='abc'print(str(a)+c)print(a + b)
result:
80 abc
169
The type function cannot be displayed directly, and other functions need to be called to display such as print.
b =89
c ='abc'print(type(b))print(type(c))
result:
< class'int'><class'str'>
One-way judgment, two-way judgment, and multi-way judgment can be used, among which two-way judgment and multi-way judgment do not need to add conditional judgment after else, so it needs to be put at the end
8.1 One-way judgment
a =80if a >100:print('a is greater than 100')
8.2 Two-way judgment
a =80if a >100:print('a is greater than 100')else:print('a is less than 100')
8.3 Multidirectional judgment
a =55if a >90:print('Great God')
elif a >60:print('Pass')else:print('不Pass')
a = 1 assignment (variable assignment)
a == 1 is equal to (compare, judge)
For the above two, an equal sign is used to assign a value to a variable, and two equal signs are used for comparison and judgment
If condition is judged, there must be four spaces between the child condition judgement and the parent condition judgement if.
if parent condition:
if sub-condition 1:
elif sub-condition 2:else:
elif mother condition 2:if sub-condition 1:
elif sub-condition 2:else:else:if sub-condition 1:
elif sub-condition 2:else:
Recommended Posts