In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to change tuples in python". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to change tuples in python" can help you solve your doubts.
1. List (List)
A tuple is a sequence of square brackets. After the list is created, you can change its content according to your own needs.
> list= [1, list [0] = 8 > list [6] = 0 > list [8,2]
You can add new data to the list:
> > len (list) # to see how many data there are in this list 6 > list.append (7) # insert > list [8,2,3,4,5,6,7] > len (list) 7 > > list.insert (3d10) # insert data anywhere in the list, the first parameter represents the index, and the second parameter represents the inserted data > list [8,2,3,10,4,5,6,7] > > 2. Tuple (Tuple)
A tuple is a sequence of a pair of parentheses. After the tuple is created, it is not allowed to change, that is, its content cannot be modified and its size cannot be changed.
> > tuple= > > tuple > > tuple [2] 3 > tuple [2] = 8Traceback (most recent call last): File ", line 1, in tuple [2] = 8TypeError: 'tuple' object does not support item assignment
Although tuples do not support resizing, you can merge two tuple.
>
Although values in tuples are not allowed to be changed directly, we can use lists to change values in tuples, we can use the function list () to turn tuples into lists, and we can use the function tuple () to convert lists into tuples.
> t = (5631pc103, "Finn", "Bilous", "Wanaka", "1999-09-22") > print (t) (5631103c, "Finn", "Bilous", "Wanaka", "1999-09-22") > lst = list (t) > print (lst) [563110310, "Finn", "Bilous", "Wanaka", "1999-09-22"] > > lst [4] = 'LA' > > t = tuple (lst) > > print (t) (5631103, "Finn", "Bilous", "LA", "1999-09-22")
The in keyword can be used to find the specified value in the tuple, and the function index () can be used to return the index of the found value in the tuple.
N=103if n int: # find indexn in tuple t = t.index (n) # find the index value of the value in the tuple (from 0) print (indexn)
Output result:
one
N = "Finn" if n int: indexn = t.index (n) print (indexn)
Output result:
two
After reading this, the article "how to change tuples in python" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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.