[Basic knowledge of python] 4. Lists and dictionaries

Preface

So far, we have mastered 3 data types: integers, floating point numbers, and strings. In this level we will learn two new data types: lists and dictionaries.

But before that, I want to talk to you about the inextricable relationship between "computer" and "data".

The word "computing" is in the name of a computer. If a computer is separated from data, it will be like a clever woman unable to make a meal without straw. Therefore, data is very important to computers.

In general, computers use data in three ways:

Insert image description here

The first one: Use data directly, such as the print() statement, which can directly print out the data we provide. Usually what you see is what you get.

# 直接运行即可
# print()会直接把我们提供的数据打印出来

print(3)
print('欢迎来到第4关')

operation result:

3
欢迎来到第4

The second type: calculating and processing data, let’s look at an example:

# 直接运行即可
# 计算机会先计算/加工 数据,再用print()语句打印

print(3+2*3)
print('欢迎来到'+'第4关')

operation result:

9
欢迎来到第4

For these two print statements, the computer first [calculates and processes the data], and then prints the data in the print() brackets to the screen.

Let’s look at the third type: using data to make judgments.

# 直接运行即可
# 计算机会使用数据来做判断

a = int(input('请输入你的年龄:'))
#如果输入不了数字,请切换成英文输入法

if a<0:
    print('你还在娘胎里呢。')
elif a == 0:
    print('欢迎来到这个世界。')
elif a < 18:
    print('小小的年纪还不懂什么是爱')
else:
    print('你已经是个成熟的大人了,要学会照顾自己。')

operation result:

请输入你的年龄:28
你已经是个成熟的大人了,要学会照顾自己。

It can be seen that the computer here is [using data to make logical judgments]:

Insert image description here
Now we have a certain understanding of the relationship between [computer] and [data]. Precisely because of the importance of data, for novice programmers, mastering the main data types is a top priority.

At this level, we will come into contact with two new data types - lists and dictionaries. You will find that they are more advanced and "inclusive" than the "integers, floating point numbers, and strings" we have learned.

Why do you say that? For the types learned earlier, only one piece of data can be saved per assignment. If we need to use a lot of data, it will be very inconvenient.

The role of lists and dictionaries is to help us store large amounts of data for computers to read and operate.

list

First let's look at the list. To feel the power of the list, let's play a role-playing game: from now on, you are the teacher of a new class!

On the first day, 50 fresh faces came to the class. You ask students to write their names on the roster so that they can be called one by one during class.

If we can only use the knowledge we have learned to solve this problem, we need to assign each student's name to a variable name and then print it separately. The code is like this:

#快速扫一眼,直接点击运行

student1 = '党志文' 
student2 = '浦欣然'
student3 = '罗鸿朗'
student4 = '姜信然'
student5 = '居俊德'
student6 = '宿鸿福'
student7 = '张成和'
student8 = '林景辉'
student9 = '戴英华'
student10 = '马鸿宝'
student11 = '郑翰音'
student12 = '厉和煦'
student13 = '钟英纵'
student14 = '卢信然'
student15 = '任正真'
student16 = '翟彭勃'
student17 = '蒋华清'
student18 = '双英朗'
student19 = '金文柏'
student20 = '饶永思'
student21 = '堵宏盛'
student22 = '濮嘉澍'
student23 = '戈睿慈'
student24 = '邰子默'
student25 = '于斯年'
student26 = '扈元驹'
student27 = '厍良工'
student28 = '甘锐泽'
student29 = '姚兴怀'
student30 = '殳英杰'
student31 = '吴鸿福'
student32 = '王永年'
student33 = '宫锐泽'
student34 = '黎兴发'
student35 = '朱乐贤'
student36 = '关乐童'
student37 = '养永寿'
student38 = '养承嗣'
student39 = '贾康成'
student40 = '韩修齐'
student41 = '彭凯凯'
student42 = '白天干'
student43 = '瞿学义'
student44 = '那同济'
student45 = '衡星文'
student46 = '公兴怀'
student47 = '宫嘉熙'
student48 = '牧乐邦'
student49 = '温彭祖'
student50 = '桂永怡'
print(student1+'在不在?')
print(student2+'在不在?')
print(student3+'在不在?')
print(student4+'在不在?')
print(student5+'在不在?')
print(student6+'在不在?')
print(student7+'在不在?')
print(student8+'在不在?')
print(student9+'在不在?')
print(student10+'在不在?')
print(student11+'在不在?')
print(student12+'在不在?')
print(student13+'在不在?')
print(student14+'在不在?')
print(student15+'在不在?')
print(student16+'在不在?')
print(student17+'在不在?')
print(student18+'在不在?')
print(student19+'在不在?')
print(student20+'在不在?')
print(student21+'在不在?')
print(student22+'在不在?')
print(student23+'在不在?')
print(student24+'在不在?')
print(student25+'在不在?')
print(student26+'在不在?')
print(student27+'在不在?')
print(student28+'在不在?')
print(student29+'在不在?')
print(student30+'在不在?')
print(student31+'在不在?')
print(student32+'在不在?')
print(student33+'在不在?')
print(student34+'在不在?')
print(student35+'在不在?')
print(student36+'在不在?')
print(student37+'在不在?')
print(student38+'在不在?')
print(student39+'在不在?')
print(student40+'在不在?')
print(student41+'在不在?')
print(student42+'在不在?')
print(student43+'在不在?')
print(student44+'在不在?')
print(student45+'在不在?')
print(student46+'在不在?')
print(student47+'在不在?')
print(student48+'在不在?')
print(student49+'在不在?')
print(student50+'在不在?')

operation result:

党志文在不在?
浦欣然在不在?
罗鸿朗在不在?
姜信然在不在?
居俊德在不在?
宿鸿福在不在?
张成和在不在?
林景辉在不在?
戴英华在不在?
马鸿宝在不在?
郑翰音在不在?
厉和煦在不在?
钟英纵在不在?
卢信然在不在?
任正真在不在?
翟彭勃在不在?
蒋华清在不在?
双英朗在不在?
金文柏在不在?
饶永思在不在?
堵宏盛在不在?
濮嘉澍在不在?
戈睿慈在不在?
邰子默在不在?
于斯年在不在?
扈元驹在不在?
厍良工在不在?
甘锐泽在不在?
姚兴怀在不在?
殳英杰在不在?
吴鸿福在不在?
王永年在不在?
宫锐泽在不在?
黎兴发在不在?
朱乐贤在不在?
关乐童在不在?
养永寿在不在?
养承嗣在不在?
贾康成在不在?
韩修齐在不在?
彭凯凯在不在?
白天干在不在?
瞿学义在不在?
那同济在不在?
衡星文在不在?
公兴怀在不在?
宫嘉熙在不在?
牧乐邦在不在?
温彭祖在不在?
桂永怡在不在?

But we know that in the programming world, the most taboo thing is "repetitive labor". After typing these one hundred lines of code, even if it is copied and pasted to modify, I will go crazy every minute.

In fact, as long as you learn lists and loops (spoiler: loops will be discussed in the next level, please ignore them for now), you can get it done with 3 lines of code.

#直接运行代码即可
students = ['党志文', '浦欣然', '罗鸿朗', '姜信然', '居俊德', '宿鸿福', '张成和', '林景辉', '戴英华', '马鸿宝', '郑翰音', '厉和煦', '钟英纵', '卢信然', '任正真', '翟彭勃', '蒋华清', '双英朗', '金文柏', '饶永思', '堵宏盛', '濮嘉澍', '戈睿慈', '邰子默', '于斯年', '扈元驹', '厍良工', '甘锐泽', '姚兴怀', '殳英杰', '吴鸿福', '王永年', '宫锐泽', '黎兴发', '朱乐贤', '关乐童', '养永寿', '养承嗣', '贾康成', '韩修齐', '彭凯凯', '白天干', '瞿学义', '那同济', '衡星文', '公兴怀', '宫嘉熙', '牧乐邦', '温彭祖', '桂永怡']
for i in students:
    print(i+'在不在?')

operation result:

党志文在不在?
浦欣然在不在?
罗鸿朗在不在?
姜信然在不在?
居俊德在不在?
宿鸿福在不在?
张成和在不在?
林景辉在不在?
戴英华在不在?
马鸿宝在不在?
郑翰音在不在?
厉和煦在不在?
钟英纵在不在?
卢信然在不在?
任正真在不在?
翟彭勃在不在?
蒋华清在不在?
双英朗在不在?
金文柏在不在?
饶永思在不在?
堵宏盛在不在?
濮嘉澍在不在?
戈睿慈在不在?
邰子默在不在?
于斯年在不在?
扈元驹在不在?
厍良工在不在?
甘锐泽在不在?
姚兴怀在不在?
殳英杰在不在?
吴鸿福在不在?
王永年在不在?
宫锐泽在不在?
黎兴发在不在?
朱乐贤在不在?
关乐童在不在?
养永寿在不在?
养承嗣在不在?
贾康成在不在?
韩修齐在不在?
彭凯凯在不在?
白天干在不在?
瞿学义在不在?
那同济在不在?
衡星文在不在?
公兴怀在不在?
宫嘉熙在不在?
牧乐邦在不在?
温彭祖在不在?
桂永怡在不在?

Found it? In the first line of code, the right side of the assignment number no longer has only one name like a string, but 50 names.

This is the first data type we are going to get to know - list. Below I will introduce the use of lists from 4 aspects.

what is a list

First, let's take a look at the code format of the list:
Insert image description here
['Xiao Ming', 'Xiao Hong', 'Xiao Gang'] in the picture is a list.

A list needs to use square brackets [ ] to frame the various data in it. Each data in it is called an "element". Each element must be separated by commas.

This is the standard format of the list. Now please create a list named list1. There are three elements in the list: 'Xiao Ming', 18, 1.70, and print it out:

Reference answer:

list1=['小明','18','1.70']
print(list1)

Congratulations, you have successfully mastered the standard way of writing lists and how to print lists. Moreover, you have also verified a knowledge point with code: lists are very inclusive, and all types of data (integers/floating point numbers/strings) can be included.

However, many times, we only need to use a certain element in the list. For example, when the teacher takes roll call in class, he will not say "all students stand up and answer this question."

So, the question is: how to remove a specific element in the list?

Extract a single element from a list

This involves a new knowledge point: offset. The various elements in the list, like a row of students in a classroom, are arranged in order, that is, each element has its own position number (i.e. offset).

Insert image description here

From the picture above, we can see: 1. The offset starts from 0, not 1 as we are used to; 2. Adding square brackets with offset after the list name can get the element at the corresponding position.

Therefore, we can index the list by offset (can be understood as search positioning) and read the elements we need.

If you want to call Xiao Ming to answer a question now, how would you write it in code? Please add the following code to print out the element 'Xiao Ming' using the offset of the list.

students = ['小明','小红','小刚']

Reference answer:

students = ['小明','小红','小刚']
print(students[0])    

Now that we know how to remove an element from a list, what if we want to remove several elements at the same time? So let's learn how to remove multiple elements from a list.

Extract multiple elements from a list

This time, I will not directly tell you the knowledge you need to use, but I want you to summarize the rules yourself.

Please run the following code, compare the final results of the code and the terminal, and try to find the rules. I'll test you later.

A reminder: The numbers on the left and right of the following refer to the offset of the element in the list. Remember that offsets (indexes) always start from 0.

list2 = [5,6,7,8,9]
print(list2[:])
print(list2[2:])
print(list2[:2])
print(list2[1:3])
print(list2[2:4])

operation result:

[5, 6, 7, 8, 9]
[7, 8, 9]
[5, 6]
[6, 7]
[7, 8]

The above operation of using colons to intercept list elements is called slicing. As the name suggests, it is to take out a certain fragment of the list for processing. This slicing method allows us to remove multiple elements from the list.

list2 = [5,6,7,8,9]

print(list2[:])
# 打印出[5,6,7,8,9]
print(list2[2:])
# 打印出[7,8,9]
print(list2[:2])
# 打印出[5,6]
print(list2[1:3])
#打印出[6,7]
print(list2[2:4])    
#打印出[7,8]

From this we can conclude:

First half of the sentence: If the left side of the colon is empty, the element must be fetched from the offset of 0; if the right side is empty, the last element of the list must be fetched.
The second half of the sentence: The element corresponding to the number on the left side of the colon should be taken, but the element on the right side should not be moved (you can review the code again).

Now please try it out. Please modify the code and use slicing to take out the two elements Xiaoming and Xiaohong from the list together.

students = ['小明','小红','小刚']

Reference answer:

students = ['小明','小红','小刚']
print(students[:2])

In addition, we need to pay attention to one detail: the offset obtains the elements in the list, while slicing intercepts a certain part of the list, so it is still a list. Please run the following code to take a look.

students = ['小明','小红','小刚']
print(students[2])
print(students[2:])

operation result:

小刚
['小刚']

After learning how to remove elements from a list, let's look down.

Add/remove elements to list

A week later, while you were in class, the dean suddenly picked up a new student, "Xiao Mei," who said he was a transfer student and wanted to join your class. At this time, we need to use the append() function to add elements to the list. Append means to append or supplement.

Let's try it through the code. Please run the code and think about the rules: (Note: After reporting an error, you can read the error message, then add a # sign at the beginning of line 6, comment it out and run it again)

# 请运行以下代码:报错后,可读一下报错信息,然后将第6行注释掉再运行。
list3 = [1,2]
list3.append(3)
print(list3)

list3.append(4,5)
list3.append([4,5])
print(list3)

Have you discovered the pattern? Let’s interpret the error message and code results:

Insert image description here
What this sentence means is: the brackets after append can only accept one parameter, but two are given, namely 4 and 5. Therefore, when append() is used to add elements to the list, only one element can be added at a time.

At the same time, it can be seen from the successful operation of list3.append([4,5]) in line 7:

1. The elements in the list can be strings, numbers, etc., or they can be the list itself (that is, the list supports nesting) 2. The
parameters after the append function only need to satisfy the number of one (a single list will also be regarded as one element )
3. The elements after append will be added to the end of the list.

The append function does not generate a new list, but adds an element to the end of the list. Moreover, the list length is variable and the theoretical capacity is unlimited, so arbitrary nesting is supported.

Now, please add Xiaomei to the students list and print out the list. Note that the format is list name.append():

Reference answer:

students = ['小明','小红','小刚']
students.append('小美')
print(students)

Great! Now you know how to add elements to your list.

It’s another new day, and you get a call. Xiaohong is sick and has asked for leave. She won’t come to class today. So, you want to remove Xiaohong from the list.

Tip: You need to use the del statement. Please read the explanation of the "del statement" in Python's official documentation first: (Knowing how to read official documentation is also an important ability in programming learning)

Insert image description here
Please complete the following code based on the knowledge in the above picture, delete 'Little Red' from the list, and print it out: (The syntax is: del list name [index of element])

students = ['小明','小红','小刚','小美']
print(students)

Reference answer:

students = ['小明','小红','小刚','小美']
del students[3]
print(students)

In fact, the del statement is very convenient. It can delete one element or multiple elements at once (the principle is similar to slicing, taking the left but not the right).

At this point, we have gone through the basic overview of the list, and it is time to summarize:

Insert image description here
Once you have mastered these and the data type of list, you are ready to get started. The follow-up is to continue to accumulate experience in exercises and projects and make full use of the list. Next we will learn about another data type.

Data type: dictionary

As we all know, a teacher's daily routine is to write and correct papers. In this midterm exam, Xiao Ming, Xiao Hong, and Xiao Gang scored 95, 90, and 90 points respectively.

If we still use lists to store data, we need to create a new list specifically to hold the scores, and make sure they are in the same order as the names, which is very troublesome.

Therefore, if there is a one-to-one correspondence between two types of data such as names and numerical values ​​(such as scores, height, weight, etc.), it will be more convenient to store them using the second data type - "dictionary".

what is dictionary

Similarly, let’s first take a look at what a dictionary looks like:
Insert image description here
Look carefully, dictionaries and lists have three things in common: 1. They have names; 2. Use = for assignment; 3. Use commas as separators between elements. separator.

There are two differences: 1. The outer layer of the list is square brackets [ ], and the outer layer of the dictionary is braces { };

students = ['小明','小红','小刚']
scores = {
    
    '小明':95,'小红':90,'小刚':90}

2. The elements in the list are self-contained, while the elements in the dictionary are composed of key-value pairs, connected by English colons. For example, 'Xiao Ming': 95, where we call 'Xiao Ming' the key and 95 the value.

The combination of such a unique key and the corresponding value is called a [key-value pair]. The above dictionary has three [key-value pairs]: 'Xiao Ming': 95, 'Xiao Hong': 90, and 'Xiao Gang' :90

If we don't want to do the math verbally, we can use the len() function to get the length (number of elements) of a list or dictionary, and put the name of the list or dictionary in parentheses.

#直接运行代码即可
students = ['小明','小红','小刚']
scores = {
    
    '小明':95,'小红':90,'小刚':90}
print(len(students))
print(len(scores))

operation result:

3
3

What needs to be emphasized here is that the keys in the dictionary are unique, but the values ​​are repeatable.

If you accidentally declare two [key-value pairs] with 'Xiao Ming' as the key, the [key-value pair] that appears later will overwrite the previous [key-value pair].

# 请你运行下面的代码:
scores = {
    
    '小明': 95, '小红': 90, '小明': 90}
print(scores)

operation result:

{
    
    '小明': 90, '小红': 90}

Extract elements from dictionary

Now, we try to print out Xiao Ming's grades from the dictionary. This involves the indexing of the dictionary. Unlike lists that are indexed by offsets, dictionaries rely on keys.

# 请你运行下面的代码:
scores = {
    
    '小明': 95, '小红': 90, '小刚': 90}
print(scores['小明'])

operation result:

95

This is how to extract the corresponding value from the dictionary. Similar to a list, [ ] is used, but because the dictionary has no offset, the name of the key should be written in square brackets, that is, the dictionary name [key of the dictionary].

Now please print out Xiaohong's results and type the code yourself so that you can master it quickly.

Reference answer:

scores = {
    
    '小明':95,'小红':90,'小刚':90}
print(scores['小红'])    

Now you also know how to retrieve values ​​from a dictionary.

After Xiaogang got the test paper, he came to you after class and said that his total score was calculated incorrectly and should be 92 points. You took a look and found that it really was. So, you crossed out 90 on your grade book and changed it to 92.

This operation corresponds to the deletion and addition of the dictionary in the code.

Add/remove elements to dictionary

Let’s take a look at an example first. Run the following code and pay attention to how the dictionary is deleted and key-value pairs are added:

# 直接运行下面的代码,留意字典以及新的键值对是如何增加的:

album = {
    
    '周杰伦':'七里香','王力宏':'心中的日月'}
del album['周杰伦']
print(album)

album['周杰伦'] = '十一月的萧邦'
print(album)
print(album['周杰伦'])

operation result:

{
    
    '王力宏': '心中的日月'}
{
    
    '王力宏': '心中的日月', '周杰伦': '十一月的萧邦'}
十一月的萧邦

We can find that the code to delete key-value pairs in the dictionary is the del statement del dictionary name [key], and to add a new key-value pair, the assignment statement dictionary name [key] = value is used.

So, please change Xiaogang's score to 92 points. By the way, the new Xiaomei also took the exam and got an 85. Please make modifications and additions to the dictionary, and then print out the entire dictionary.

How's it going? Is it done? The reference answer is this:

scores = {
    
    '小明':95,'小红':90,'小刚':90}
del scores['小刚']
scores['小刚'] = 92
scores['小美'] = 85
print(scores)

alright. At this point, we can summarize the basic knowledge of dictionaries:

Insert image description here

Similarities and Differences between Lists and Dictionaries

Lists and dictionaries are both data types that can store multiple pieces of data in Python. They have many things in common, but there are also differences worthy of our attention. So let’s take a look at the differences first.

The difference between lists and dictionaries

A very important difference is that the elements in the list have their own clear "position", so even if they appear to be the same elements, as long as they are in different positions in the list, they are two different elements. Let's take a look at the code:

# 如果==左右两边相等,值为True,不相等则为False。
print(1 == 1)  
# 1等于1,所以值为True

print(1 == 2)
# 1不等于2,所以为False

students1 = ['小明','小红','小刚']
students2 = ['小刚','小明','小红']
print(students1 == students2)

scores1 = {
    
    '小明':95,'小红':90,'小刚':100}
scores2 = {
    
    '小刚':100,'小明':95,'小红':90}
print(scores1 == scores2)

operation result:

True
False
False
True

In comparison, dictionaries are much more easy-going, and the order of transfer does not affect them. Because the data in the list is arranged in order, while the data in the dictionary is arranged randomly.

This is also the reason why the two data reading methods are different: if the list is ordered, offset positioning is used; if the dictionary is unordered, the value is obtained through a unique key.

Similarities between lists and dictionaries

Let's first look at the first common point: in lists and dictionaries, if you want to modify elements, you can use assignment statements to complete it. Take a look at the code:

list1 = ['小明','小红','小刚','小美']
list1[1] = '小蓝'
print(list1)

dict1 = {
    
    '小明':'男'}
dict1['小明'] = '女'
print(dict1)

operation result:

['小明', '小蓝', '小刚', '小美']
{
    
    '小明': '女'}

Therefore, when modifying Xiaogang's score above, you can actually use the assignment statement directly. The del statement is usually used to delete key-value pairs that are definitely unnecessary.

scores = {
    
    '小明':95,'小红':90,'小刚':90}
#del scores['小刚']
#如果只需要修改键里面的值,可不需要del语句
scores['小刚'] = 92

The second common point has actually been mentioned slightly before, that is, it supports arbitrary nesting. In addition to the data types learned before, lists can be nested within other lists and dictionaries, and dictionaries can also be nested within other dictionaries and lists.

Let’s look at the first case first: lists nested lists. You set up a study group of four people in your class. At this time, the list can be written as:

students = [['小明','小红','小刚','小美'],['小强','小兰','小伟','小芳']]

The students list is composed of two sublists. Now there is a question: How do we get Xiaofang out?

Maybe you count Xiaofang as the 7th element in the list (starting from 0), so don't you think students[7] can get Xiaofang?

Of course, things are not that simple. When we extract such multi-level nested lists/dictionaries, we have to extract them layer by layer, just like peeling an onion:

Insert image description here
Now, we have determined that Xiaofang is in the list of students[1], let's continue reading.

Insert image description here
Xiaofang is the element with offset 3 in the students[1] list, so to remove Xiaofang, the code can be written like this:

students = [['小明','小红','小刚','小美'],['小强','小兰','小伟','小芳']]
print(students[1][3])

Now, use your ingenuity and take Xiaolan off the list and print it out.

Reference answer:

students = [['小明','小红','小刚','小美'],['小强','小兰','小伟','小芳']]
print(students[1][1])    

Next, let's look at the second case: dictionary nested dictionary.

It is similar to nested lists. It needs to be taken out layer by layer. For example, if you want to take out Xiaofang’s grades, the code is written like this:

scores = {
    
    
    '第一组':{
    
    '小明':95,'小红':90,'小刚':100,'小美':85},
    '第二组':{
    
    '小强':99,'小兰':89,'小伟':93,'小芳':88}
    }
print(scores['第二组']['小芳'])

Please observe the above code carefully, and then try to get Xiaogang's results.

Reference answer:

scores = {
    
    
    '第一组':{
    
    '小明':95,'小红':90,'小刚':100,'小美':85},
    '第二组':{
    
    '小强':99,'小兰':89,'小伟':93,'小芳':88}
    }
print(scores['第一组']['小刚'])

Let's increase the difficulty again and see how lists and dictionaries are nested into each other. We can combine code and comments to see it.

# 最外层是大括号,所以是字典嵌套列表,先找到字典的键对应的列表,再判断列表中要取出元素的偏移量
students = {
    
    
    '第一组':['小明','小红','小刚','小美'],
    '第二组':['小强','小兰','小伟','小芳']
    }
print(students['第一组'][3])
#取出'第一组'对应列表偏移量为3的元素,即'小美'

# 最外层是中括号,所以是列表嵌套字典,先判断字典是列表的第几个元素,再找出要取出的值相对应的键
scores = [
    {
    
    '小明':95,'小红':90,'小刚':100,'小美':85},
    {
    
    '小强':99,'小兰':89,'小伟':93,'小芳':88}
    ]
print(scores[1]['小强'])
#先定位到列表偏移量为1的元素,即第二个字典,再取出字典里键为'小强'对应的值,即99。

Similarly, please try it yourself now. Based on the following code, please 1. Print out Xiaogang in the dictionary students 2. Print out Xiaogang’s score 100 in the list scores.

Reference answer:

students = {
    
    
    '第一组':['小明','小红','小刚','小美'],
    '第二组':['小强','小兰','小伟','小芳']
    }
scores = [
    {
    
    '小明':95,'小红':90,'小刚':100,'小美':85},
    {
    
    '小强':99,'小兰':89,'小伟':93,'小芳':88}
    ]
print(students['第一组'][2])
print(scores[0]['小刚'])    

I believe you can make it successfully? Applause for you! Congratulations on getting to know these two new friends one step closer.

So, the task of this level has been successfully completed. Remember to review more and do exercises after class, which can help you consolidate the knowledge you have learned better and faster.

In the next level, we will start to come into contact with a very important tool in Python - loop. With it, many repetitive tasks can be done by the computer for us. See you in the next level!

Guess you like

Origin blog.csdn.net/qq_41308872/article/details/132689954