Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the python type conversion function

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use python type conversion functions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Similar to and operation

Similar to or operation

# Type conversion # sortedli= [2magne 45pr 1je 67je 23je 10] li.sort () # list sorting method print (li)

# sortedli= [2 li.sort () # list sorting method print (li) # sorted () sorted (li) print (li)

# Type conversion # sortedli= # li.sort () # list sorting method print (li) # sorted () varli=sorted (li) # ascending print (varli) varli2=sorted (li,reverse=True) # descending print (varli2)

TupArray= (2 tupArray,reverse=False 34 print 5 print 6 6 4 3 2 90) # tuple sort varRs=sorted (tupArray,reverse=False) print (varRs)

# zip for packaging S1 = ['you','me','he'] print (list (zip (S1) # there is only one element after compression. When there is only one element in the tuple, there is a comma print (list (zip (S1) # compress two data The data needs to be converted into a list before it can be printed. According to the index, the elements of the corresponding index position in the sequence will be stored as a tuple for output. If the number of the two elements is not the same, it will be compressed according to the least number of elements.

S1 = ['you','me','he'] S3 = ['you','me','he', ''] print (list (zip (S1) # there is only one element after compression. When there is only one element in the tuple, there is a comma print (list (S1parade S3)) # Compression of two data. You need to convert the data into a list before you can print it out.

Assemble Book Information with zip

# enumeratelistObj=] # indexed output for item in enumerate (listObj): print (item)

# enumeratelistObj=] # indexed output for index,item in enumerate (listObj): # Index accepted by index print (item)

# enumeratelistObj=] # indexed output for index,item in enumerate (listObj,5): # specify that the index subscript starts at 5 (index,item)

# ergodic dictionary dicObj= {} dicObj ['name'] =' Xiaoling 'dicObj [' hobby'] = 'Xiaoling' dicObj ['pro'] =' Xiaoling 'print (dicObj) for item in enumerate (dicObj): print (item)

# traversal dictionary dicObj= {} dicObj ['name'] =' Xiaoling 'dicObj [' hobby'] = 'Xiaoling' dicObj ['pro'] =' Xiaoling 'print (dicObj) for index,item in enumerate (dicObj): # use the subscript variable to accept print (item)

Thank you for reading! This is the end of this article on "how to use the python type conversion function". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report