1 naming conventions for variable names:
Consists of numbers, letters, and underscores, but you cannot name a variable with a number. For example A, B, C, name, User1 user_id, and so on can be used as variable names.
1A,2B 3CD and so on are not. Special Note that you cannot use keywords in python syntax as variable names. Common "Class" "and" "as" "Insert" "while" "Elif" "Else" "Del" and so on.
Variables in Python do not need to be declared and are used directly.
2 Input usage
Wait for user input.
Enclosed in double quotation marks in parentheses to display the contents before the input
>>> n=input ("pleaseinput your name:") Carriage return please input your Name:huo
3 Print Usage
Output specified information
1 Direct Output English characters
Print ("huo") Huo
2 Direct output Chinese character print(" hello ") Hello
3 output variable refers to the content (without quotation marks at this time)>>> n="helloWorld"print(n) Hello World
4 If Else usage
Determine if the condition is set up, then execute the IF code block otherwise execute else
A=input ("Pleaseinput A:") b=input ("pleaseinput b:" #If condition: Enter write code block note that the code block and if are staggered if a<b: # determine if A is less than B Print(a)# If A is less than B perform else: print(b) # otherwise execute else
Run results
Please input a:2/input B:
Please input a:4/input B:
If statement supports nesting
#找出三个数中的最大一个
A=input () b=input () C=input () T="0"ifa<B:t=a A=b b=Tifa<C:Print(c)Else: Print(a)Else: ifa<C:Print(c)Else: Print(a)
Run results
================== restart:c:/users/shinelon/desktop/1.py ==================1323>>> ================== restart:c:/users/shinelon/desktop/1.py ==================4656
Elif similar to else if
A=input () b=input () C=input () T="0"ifa<B:t=a A=b b=Tifa<C:t=a A=C c=TelifA>B:ifa<C:t=a A=C c=Tifb<C:t=b b=C c=TPrint(a)Print(b)Print(c)
While usage
Looping statements
Example
Name=input ("Please input your name:") Count=0 whileCount<3: passwd=input ("Please input your password:") ifpasswd=="393407505": Count=3Print("Log in successfully! ") Else: Print("Log in failed") Count=count+1
Run results
Please input your name:huoplease input your password:11111 Log in failed please input your password:11111 Login failed please input your password:11111 Login failed >>> ================== restart:c:/users/shinelon/ desktop/1.py ================== Pleaseinput your name:huoplease input your password:393407505 log in successfully!
Summary: It is more important to practice more ideas!
Python Basics (1)--input print if Else elif while usage notes