-
Run Python
mode 1: Python interactive mode
Step: cmd + Enter
Input: python
Input: print (“hello world”)
Enter
Exit: exit()
-
Method 2: Integrated Development Environment
Step: print("hello world") -
Method 3 Command line execution script
Step python+script
Case python hello.py -
Basic syntax
in Python Variable definition Python
variable name = value
name = Zhang San
View variable type
print(type(name))
-
Identifiers
Some symbols and names customized by developers in the program
Identifiers are defined by themselves, such as variable names, function names
Naming rules
for identifiers. Identifiers can only consist of letters, underscores "_", and numbers.
. Identifiers cannot start with a digit.
. Identifiers cannot use keywords
. Identifiers are case sensitive.
(Suggestion: Identifier naming should "see the name and know the meaning")
关键字
[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’,
‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’,
‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’, ‘or’,
‘pass’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]
标识符符合规则
if name and my_list my_list1 from#1 age 2list as True
wetyui height my_log qwe&qwe
Identifier naming method
Small camel case: addName
Large camel case: AddName
-
Input and output of Python
Input: input("Prompt information:")
Output: print("The output is:")
Newline: /n
7. Format the output Method 1: Format the print
with a percent sign (%) string
(“my name is %s, and my age is %d” %(name,age))
-
print(“my name is {}, and my age is {}”.format(age,name))
-
Notes
-
operator
If x is false, x and y return the value of x else return the computed value of y
X is true, return the value of x, otherwise it returns the computed value of y
if x is true return false if false if x is false it returns true
11. Data type
Number (number)
String (string)
List (list)
Tuple (tuple)
Set (collection)
Dictionary (dictionary)
The relationship of the six
immutable data (3): Number (number), String (string) , Tuple (tuple);
variable data (3): List (list), Dictionary (dictionary), Set (collection).