Python basics and its basic syntax

  1. Run Python
    mode 1: Python interactive mode
    Step: cmd + Enter
    Input: python
    Input: print (“hello world”)
    Enter
    Exit: exit()
    insert image description here

  2. Method 2: Integrated Development Environment
    Step: print("hello world")insert image description here

  3. Method 3 Command line execution script
    Step python+script
    Case python hello.pyinsert image description here

  4. Basic syntax
    in Python Variable definition Python
    variable name = value
    name = Zhang San
    View variable type
    print(type(name))
    insert image description here

  5. 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

  1. Input and output of Python
    Input: input("Prompt information:")
    Output: print("The output is:")
    Newline: /n
    insert image description here7. Format the output Method 1: Format the print
    with a percent sign (%) string
    (“my name is %s, and my age is %d” %(name,age))
    insert image description here

  2. print(“my name is {}, and my age is {}”.format(age,name))
    insert image description here

  3. Notes
    insert image description here

  4. operator
    insert image description here
    insert image description here
    insert image description here
    insert image description here

insert image description here
If x is false, x and y return the value of x else return the computed value of y
insert image description here
X is true, return the value of x, otherwise it returns the computed value of y
insert image description here
if x is true return false if false if x is false it returns true
insert image description here
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).

Guess you like

Origin blog.csdn.net/weixin_44826661/article/details/123999311