Re-learn Python, learn python
Tuples
Tuples: The feature is that the content is not changeable and the read-only list can be queried and cannot be modified.
a = 2,print(a)print(type(a))b = ('a','b','c')print(b[1])
Running result:
(2,)<class 'tuple'>b
Dictionary
Dictionary: Internal data is unordered during printing, and key values are hashed and unique.
# Create a dictionary a = {'A': 'python', 'B': 'Ruby ', 'C': 'java'} # directly create a dictionary print () # built-in dictionary method creation: dicta = dict ('A', 'B'),) print (a) a = dict ([['A ', 'B'],]) print (a) # modify Dictionary a = {'A': 'B'} set1 =. setdefault ("c", "java") print (a) print (set1) # query operation a = {'A': 'python', 'B': 'ruby ', 'C': 'java'} print (. keys () print (. values () print (. items () print (a ['a']) # update method a = {'A': 'python', 'B': 'ruby', 'C ': 'java'} B = {'D': 'shell'}. update (B) print (a). update ({'A': 'javascript '}) print (a) # Delete method a = {'A': 'python',' B ': 'ruby ', 'C': 'java'}. clear () print (a) # clear the dictionary a = {'A': 'python', 'B': 'Ruby ', 'C ': 'java'} del a ['a'] print (a) print ("********************") a = {'A': 'python', 'B': 'ruby', 'C': 'java'} B =. pop ('B') print (a) print (B) print ("********************") a = {'A': 'python', 'B': 'ruby', 'C': 'java'} B =. popitem () print (a) print (B) a = {'A': 'python', 'B': 'ruby', 'C ': 'java'} del a # print ('other dictionary method') a = {'first': 'python'} B = dict. fromkeys (['A', 'B'], ['test']) print (a) print (B) print ('dictionary traversal ') a = {'A': 'python', 'B': 'ruby', 'C': 'java'} for I, j in. items (): print (I, j) for I in a: # efficiency is higher than print (I, a [I])
String
List only a few simple applications
Print ('join string merging method') a = ['python', 'ruby', 'java'] B = ''. join (a) print (B) c = '*'. join (a) print (c) print ('string common method') a = 'python py' print (. count ('P') print (. capitalize () print ("format output") a = "my favorite book {name} and {name2}" print (. format_map ({'name': 'python', 'name2': 'java'}) print (. format (name = 'shell', name2 = 'bash') print (. isdigit ())
PS:
The data type in the early stage is only the foundation. If you have mastered the commonly used built-in functions, you can continue to consolidate the basic syntax when learning functions and object advanced topics.
When I was reading python at work today, I was despised by c ++'s development. It's too simple to say. Well, let's continue to work.