Python learning day3 -- python basics, pythonday3 -- python
1. python does not need to declare the type of the variable. python judges it at runtime.
2. Try not to splice strings with "+". during runtime, a memory space will be opened up for each "+", and the string will be spliced using the following method.
msg='''information of user %s-----------------------name: %sage : %djob : %s-----------end---------'''%(name,name,age,job)print(msg)
3. List syntax and exercises
In python, lists are called arrays in other languages.
1 # name List 2 name = ["mark", "jack", "Tang long"] 3 age = 9 4 # any type can be put in the list, you can also set the variable 5 name = ["mark", "jack", "Tang long", 22, age, 6, 7] 6 # List Value 7 print ("name -----", name) 8 print ("name [1] -----", name [1]) 9 print ("name [-1] -----", name [-1]) 10 print ("name [0: 6] -----", name [0: 6]) 11 print ("name [: 6] -----", name [: 6]) 12 print ("name [: 6] [2: 4] ---", name [: 6] [2: 4]) 13 print ("name [: 6] [2: 4] [0] ---", name [: 6] [2: 4] [0]) 14 print ("name [: 6] [2: 4] [0] [1] ---", name [: 6] [2: 4] [0] [1]) 15 print ("name [-5:-1] -----", name [-5:-1]) 16 print ("name [-5:] -----", name [-5:]) 17 18 # modify 19 name [1] = "Wangminghu" 20 print ("name =", name) 21 # insert, only one 22 name can be inserted at a time. insert (2, "MingGou") 23 print ("name =", name) 24 # append 25 name. append ("Alex") 26 print ("name =", name) 27 # Delete 28 name. remove ("MingGou") 29 print ("name =", name) 30 31 # running result 32 name ----- ['mark', 'jack ', 'Ang long', 22, 9, 56, 22, 47, 88, 9, 5, 6, 7] 33 name [1] ----- jack34 name [-1] ----- 735 name [0: 6] ----- ['mark', 'jack', 'hang long', 22, 9, 56] 36 name [: 6] ----- ['mark', 'jack', 'hang long', 22, 9, 56] 37 name [: 6] [2: 4] --- ['ang long', 22] 38 name [: 6] [2: 4] [0] --- Tang long39 name [: 6] [2: 4] [0] [1] --- a40 name [-5:-1] ----- [88, 9, 5, 6] 41 name [-5:] ----- [88, 9, 5, 6, 7] 42 name === ['mark', 'hanginghu', 'hang long', 22, 9, 56, 22, 47, 88, 9, 5, 6, 7] 43 name === ['mark', 'hanginghu', 'minggou', 'hang long', 22, 9, 56, 22, 47, 88, 9, 5, 6, 7] 44 name === ['mark', 'hanginghu', 'minggou', 'hang long ', 22, 9, 56, 22, 47, 88, 9, 5, 6, 7, 'Alex '] 45 name === ['mark', 'hangzhou ', 'Ang long', 22, 9, 56, 22, 47, 88, 9, 5, 6, 7, 'Alex ']List usage