Python basics 01 and python01
Main content:
- Output
- Note
- Identifier
- Variable
- Data Type
- Operator
- Indent
Output "Hello, Python"
Output in shell mode
>>> print("Hello,Python")Hello,Python
Annotation method 1. Single line annotation #
Method 2. Multi-line comment... three quotation marks
#print("Hello,Python!")print("Hello,Python!")'''print(hello)print(python)'''
Identifier (name the variable)
Symbol used to mark something
Rule: (1) first letter: letter + underline
a_ba3_a123
Variable
Variable recovery
Python does not need to define data types.
Reclaim variable
>>> a=1>>> a1>>> print(type(a))<class 'int'>>>> a=1.3>>> a1.3>>> print(type(a))<class 'float'>>>>
+ =
A + = 1
>>> a=1>>> a+=1>>> a2
Data Type
Common Python data types:
Number, String, list, tuple, set, and disctionary)
List: []
>>> L[]>>> L=["My","your"]>>> L['My', 'your']>>> L[0]'My'>>> L[1]'your'>>> L[1]="Me">>> L['My', 'Me']
Tuple :() data in the ancestor cannot be modified
>>> t=("My","You")>>> t('My', 'You')>>> t[0]'My'>>> t[1]'You'>>>
Set
>>> a="dasdsada">>> b="dasdadadddaa">>> sa=set(a)>>> sa{'a', 'd', 's'}>>> sb=set(b)>>> sb{'a', 'd', 's'}>>> sa&sb{'a', 'd', 's'}>>>
Dictionary {key1: value1, key2: value2}
>>> d={'name':'duxiao','age':'25'}>>> d{'name': 'duxiao', 'age': '25'}
1 >>> d['name']2 'duxiao'3 >>> d['age']4 '25'5 >>>
Operator
+-*/% Add subtraction, multiplication, division, and remainder
Operator priority mathematical operators are applicable to Python
Do not know the applicability (), change the priority
>>> a=2>>> b=3>>> a+b5>>> a*b6>>> a-b-1>>> a/b0.6666666666666666>>> a%b2>>> b&a2>>> 7+815
Remainder
>>> 10%31
Division not Remainder
>>> 10//33
Priority
>>> 9+5*2-118>>> (9+5)*2-127>>>
Language of indentation forced indent
Beautiful
The same level is in one indentation.
Tips for indent:
Code at the same level is in the same indentation range. The code at the next layer must be indented relative to the code at the previous level. We recommend that you use the tab key to indent the code!
a=10b=9if(a>9): print(a) if(b==9): print(b)elif(a<10): print("abc")