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
©2019-2020 Toolsou All rights reserved,
A summary of the computer retest interview questions var a = 0, b = 0; function A(a) {A = function (b)... An interview question about scope 【 Data structure and algorithm 1】 Sparse array 2020—— Net tripod cup part writeupPTA-MOOC《Python Programming Zhejiang University 》 Puzzle A Chapter 2 programming problems python closure uniapp Dynamic routing parameter transfer ( Delivery object ) How to use it Python Batch import Excel Combined use Pandas integration Lambda Expression and functional interface 【Java Details of knowledge points 3】 Serializable and Deserialize