Python Common data structures , There are several kinds of . But we use the most , Or string , list , Dictionary this 3 species .
Actually learn any programming language , The most basic thing is to learn its data structure .
take Python Come on , The concept of data structure is also super important , Different data structures , There are different functions , For us to call .
next , Let's talk about strings separately , list , How to create a dictionary .
<> String 3 Creation methods
<>① Single quotation mark (‘ ’), Create string
a = 'I am a student' print(a)
give the result as follows :
<>② Double quotation marks (“ ”), Create string
b = "I am a teacher" print(b)
give the result as follows :
<>③ Continued 3 Single quotation marks or 3 Single quotation marks , Create a multiline string
c = ''' I am a student My name is Huang Wei I am a teacher My name is Chen Li ''' print(c)
give the result as follows :
<> List of 5 Creation methods
<>① use [] Create list
a = [1,2,3] print(a)
give the result as follows :
<>② use list Create list
b = list('abc') print(b) c = list((1,2,3)) print(c) d = list({"aa":1,"bb":3})
# For dictionaries , What is generated is key list . print(d)
give the result as follows :
<>③ use range Create an integer list
e = list(range(10)) print(e)
give the result as follows :
<>④ Creating a list with list derivation
f = [i for i in range(5)] print(f)
give the result as follows :
<>⑤ use list and [] Create an empty list
g = list() print(g) h = [] print(h)
give the result as follows :
<> Lexicographic 5 Creation methods
<>① use {} Create a dictionary
a = {'name':' Chen Li ','age':18,'job':'teacher'} print(a) b = {'name':' Chen Li ','age':18,
'job':['teacher','wife']} print(b)
give the result as follows :
<>② use dict Create a dictionary
c = dict(name=' Zhang Wei ',age=19) print(c) d = dict([('name',' Li Li '),('age',18)]) print(
d)
give the result as follows :
<>③ use zip Function to create dictionary
x = ['name','age','job'] y = [' Chen Li ','18','teacher'] e = dict(zip(x,y)) print(e)
give the result as follows :
<>④ use {},dict Create empty dictionary
f = {} print(f) g = dict() print(g)
give the result as follows :
<>⑤ use fromkeys establish ’ The value is empty ’ Dictionary of
h =dict.fromkeys(['name','age','job']) print(h)
give the result as follows :
Technology
Daily Recommendation