In order to get a better understanding of the Python language, I find it very necessary to take notes.
First, based on the current trends in Python, all of the notes I've made are Python3 and above.
The following is a formal introduction to Python.
1. Computer languages generally have input and output, and Python is no exception:
Output function: print ()
Input function: input ("You can add a hint here")
2. Notes
Line comment: Add # at the beginning
Multiline Comment: Start and end with "" "or" "
3. Data type
Number (numeric):
Int:num1=12
float:num2=12.0
Complex:num3=1+2j
Str (String):
str= ' Hello World '
Print (Str[0:2])--"he #在python里面可以任意切割字符串, [0:2] means starting from 0 bits to 2nd bit but not including
Print (str[0:2]*2)--"hehe #*2 printing two times Str[0:2]
str[1]= ' t ' #报错, in Python str is not allowed to change
List (lists):
list=[' Hello ', +, ' Ben ']
list1=[' world ',%, ' Han '
Print (list[2])--"Ben
Print (List[0:2])--"[' Hello ', 21]
Print (List+list1)-"[' Hello ', ' + ', ' Ben ', ' World ', ', ' Han ']
List[1]=18;print (List[1])--"#在Python中同一行写多个语句在中间加上;
Tuple (tuple):
Tuple= (' book ', ' Next ', 17)
#与列表相似, the difference is that a tuple cannot modify
#当tuple只有宇哥元素是后面需要加上, e.g. t= (12,)
Set (SET):
set={"Yellow", "blue", "green"} #set是一个无序且不重复的序列
Dictionary (dictionary):
dic={"name": "Rose", "age": +, "Sex": "Girl"}
dic[' age ']=16 #字典通过key修改value
Dic.values () #获取所有的values
Dic.key () #获取所有的key
#创建空字典是用 {}, empty collection with ()
OK, this article is here, I hope to help you:)
One of the basics of Python