python basics -

List introduction

Think about it:

The strings learned earlier can be used to store a string of information, so think about it, how to store the names of all the students in our class?

Is it feasible to define 100 variables, each of which stores a student's name? Is there a better way?

answer:

list

<1> Format of the list

<1> Format of the list

variable A is of type list

    namesList = ['xiaoWang','xiaoZhang','xiaoHua']

More powerful than arrays in C language is that the elements in the list can be of different types

    testList = [1, 'a']

<2>Print list

demo:

namesList = ['xiaoWang','xiaoZhang','xiaoHua']
for name in namesList:
      print(name)

 

 

result:

xiaoWang
xiaoZhang
xiaoHua

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325128739&siteId=291194637