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

Collation of advanced feature knowledge points of Python

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "Python advanced features knowledge points collation". In daily operation, I believe many people have doubts about the collation of Python advanced features knowledge points. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "Python advanced features knowledge points arrangement". Next, please follow the editor to study!

Positive range value key point

The first subscript is 0

The first number is the starting subscript and the second number is the ending subscript (but the final result does not include it)

Code block 1 # forward range value-string strs = "https://www.cnblogs.com/poloyy"# starts with the 0th subscript and ends with the 1st subscript, but does not take the element of the 1st subscript, but finally takes the value of the 0 subscript print (strs [0:1]) # takes the value from the 0th subscript to the 10th subscript, but does not take the element of the 10th subscript In the end, the subscript value of print (strs [0:10]) # is taken from the 5th subscript to the 10th subscript, but not the element of the 10th subscript. Finally, the subscript value print (strs [5:10]) # is taken from the 5th subscript to the 100th subscript, but because the string is 30 characters in length. So it ends with print (strs [5print 100]) # the same number returns empty print (strs [5:5]) # the second number is smaller than the first number, empty print (strs [5:4]) # is returned from the 0th shift Take all the following elements print (strs [0:]) # take the first 10 elements print (strs [: 10]) to run the result h https://ww://ww://www.cnblogs.com/poloyyhttps://www.cnblogs.com/poloyy

Https://ww code block two # forward range values-Array lists = [1, 2, 3, 4, 5, 6, 7] print (lists [0:1]) print (lists [0:10]) print (lists [5:10]) print (lists [5print]) print (lists [5:5]) print (lists [5:4]) run result [1] [1, 2, 3, 4, 5, 6, 7] [6, 7] [6] [6] 7] [] [] reverse range value key point

Because it is reverse, the reciprocal subscript starts from-1.

The first number is the starting subscript and the second number is the ending subscript (but the final result does not include it)

If the first number is negative, the maximum of the second number is-1. If written as 0, a null value will be returned.

Code block # reverse range value-string strs = "https://www.cnblogs.com/poloyy"# takes the last 10 elements print (strs [- 10:]) # if you take the last 6-10 element, you will not get the penultimate element print (strs [- 10 print 5]) # reverse range value-list lists = [1, 2, 3, 4, 5, 6, 7, 8, 9 10] # take the last six elements print (lists [- 6:]) # take the last five elements, but will not take the penultimate element print (lists [- 5 print]) # the second value writes 0 Return null print (lists [- 10:0]) # positive number + plural combination print (lists [1:-5]) run result com/poloyycom/p [5, 6, 7, 8, 9, 10] [6, 7, 8, 9] [] [2, 3, 4, 5] [:] copy object code block # [:] lists1 = [1, 2, 3, 4, 5] lists2 = lists1lists1.append (6) print (lists1, lists2, id (lists1) Id (lists2)) lists1 = [1,2,3,4,5] lists2 = lists1 [:] lists1.append (6) print (lists1, lists2, id (lists1), id (lists2)) lists1 = [1,2,3,4,5, [1,2,3]] lists2 = lists1lists1 [5] .append (4) print (lists1, lists2, id (lists1), id (lists2)) lists1 = [1,2,3,4,5, [1,2] Lists2 = lists1 [:] lists1 [5] .append (4) print (lists1, lists2, id (lists1), id (lists2)) strs1 = "abcd" strs2 = strs1strs1 = "abc" print (strs1, strs2, id (strs1), id (strs2)) strs1 = "abcd" strs2 = strs1 [:] strs1 = "abc" print (strs1, strs2, id (strs1), id (strs2)) Operation result [1,2,3,4,5,6] [1,2,3,4,5,6] 2560550555144 25605555144 3, 4, 5, 6] [1,2,3,4,5] 2560550627784 2560548023880 [1,2,3,4]] [1,2,3,4]] [1,2,3,4] 2560550627400 2560550627400 [1,2,3,4]] [1,2,3,4,5] [1,2,3,4] 256052784 2560550627656abc abcd 256054793076 2560548937376abc abcd 256054793076 2560547976

[:] is equivalent to a shallow copy and is effective for mutable objects

Step code block # [:] strs = "https://www.cnblogs.com/poloyy"# takes the last 10 elements, 1 print every 2 (strs [- 10 print 2]) # elements 0 to 10 Take one print (strs [0: 10:5]) print (strs [:]) # reverse order print (strs [:-1]) lists = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # every 5 Take one print (lists [:: 3]) # reverse order print (lists [::-1]) every 3 to run the result cmplyh: https://www.cnblogs.com/poloyyyyolop/moc.sgolbnc.www//:sptth[1, 4, 7, 10] [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

At this point, the study on the "collation of Python advanced features knowledge points" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Servers

Wechat

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

12
Report