list :[4.0, ' string ', True], can be changed, ordered , L[n] represents the n+1 element; L[-n] denotes the penultimate nth, E.g.l[-2] It means the second last one.
Increase: l.append (' xxx ') can add xxx to the end of list, L.insert (n, ' xxx ') can add xxx to the list index n position;
Delete: Del l[n] You can remove an element with an index of n in the list; L.pop () can delete the last element in the list, L.pop (n) can delete an element with an index of n
Change: Directly re-assign value
Sort: L.sort ()
tuple tuples:(4.0, ' string ', True), cannot be changed, ordered , T[n] represents the n+1 element; T[-n] represents the nth of the penultimate, Tuples are commonly used in print statements
To eliminate () as precedence ambiguity, create a cell tuple is to add a comma, e.g.t = (1,) represents the cell tuple, t= (1) represents the integer 1
age = 22; name = ' Swaroop ';
Print '%s is%d years old '% (name, age)
Print ' Why are%s playing with that python? '% name
dictionary dict:d={key1:value1, key2:value2 }, unordered, key immutable value variable , can be through if KeyN in D See if a key exists
Increase: D[keyn]=valuen or D.setdefault (Keyn,valuen)
Delete: Del D[keyn] Remove the element with key KeyN, del d Delete dictionary, d.clear () Empty dictionary
Change: Del D[key]
Use a For loop for a dictionary if Keyn,valuen in D: | | Xxxx
Set Set: ([4.0, ' String ', True]), unordered, cannot contain duplicate elements , supports cross-and-poor set operations, iterates for X in S, adds S.add (), deletes S.remove ()
sequences : Lists, Ganso, and strings are sequences that can be used for indexing operations and slicing operations.
The list slice: L[0:3] can take the first three elements of the list, L[1:3] remove the second and third, that is, l[a,b] remove l[a] to l[b-1] elements, a=0 can be omitted.
L[:] means from beginning to end, L[::2] The third parameter indicates that each n takes one, the above l[a:b:c] from l[a] to l[b-1], every c element out of one.
Slicing the string: ' ABCDEFG ' [-3:]--> ' EFG '
Python Learning log 02_ common data types