In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge about "how to use list in Python". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
list, Chinese can be translated into a list, is used to deal with a group of ordered items of data structure. Think of your shopping list, to-do list, phone address book, etc., as a list. It's not exactly new, because we've used it before, in this sentence:
for i in range(1, 10):
#Skip a few lines here
Do you see where the list is? Try this:
print range(1,10)
The result is:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
This is a list. It is generated by range. Write the above for loop statement as:
l = range(1, 10)
for i in l:
The effect is the same.
So you can see that what the for loop does is it iterates through every item in a list, assigning the current item to a variable (here i) each time it loops through until the list ends.
Night
---------☪---------
We can also define our own list, which is a set of values surrounded by brackets and separated by commas:
l = [1, 1, 2, 3, 5, 8, 13]
You can print this list:
print l
It can also be used for... In iterates through the list, outputting each item in turn:
for i in l:
print i,
The elements in the list can also be of other types, such as:
l = ['meat', 'egg', 'fish', 'milk']
Even a mixture of different types:
l = [365, 'everyday', 0.618, True]
"How to use list in Python" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.