Python-Basic Content

Python—Basic Content

1. Identifier

  • consists of letters, numbers, and underscores, but cannot begin with a number;
  • is case sensitive, that is In Python, Value and value are two different parameters; the
  • underscore identifier has a special meaning.

2. Variable

  • Variable naming rules

    • can only contain letters, numbers, underscores, numbers cannot begin;
    • cannot use keywords and function names as variable names;
    • The name of the variable should be known as it is as short as possible.
  • Value assignment does not require type declaration

  • can assign values ​​to multiple variables at the same time

    name,sex,age = ‘frank’,‘male’,18
    ==> 
    name = ‘frank’
      sex = ‘male’
      age = 18

3.Python reserved words

The following reserved words cannot be used as constants or variables, or any other identifier Name:

​ And , exec , notassert , finally , orbreak , for , passclass , from , printcontinue , globalraisedef , if , returndel , import , tryelif , in ,whileelse , is , with , except , lambda , yield

4.print

  • print() The contents wrapped in three double quotes can be used for line feed output.
print("""
I have a jug of wine,
Can comfort the wind.
In the river,
Give a drink to the world.
""")
==>
I have a jug of wine,
Can comfort the wind.
In the river,
Give a drink to the world. 
  • end keyword, used to output the result on the same line, or add the required characters at the end of the output.
a, b = 0, 1
while b < 1000:
    print(b, end=',')
    a, b = b, a+b
==>
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,