In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how python strings access characters". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how python strings access characters".
1. To access a character in a string, such as the last character, you need to know its position in the string.
Start numbering or indexing from 0 to 1 less than the length of the string.
Str = 'Antarctica is really cold.'print (' str =', str) # first characterprint ('str [0] =', str [0]) # last characterprint ('str [- 1] =', str [- 1]) # slicing 2nd to 5th characterprint ('str [1:5] =', str [1:5]) # slicing 6th to 2nd last characterprint ('str[ 5:-2] =', str[ 5:-2])
2. If the index follows the increasing order pattern from left to right, the descending order pattern is followed from right to left.
That is, from-1,-2,-3, etc. Therefore, if you want to access the last character, you can use two methods.
Str = 'Antarctica is really cold.'a = len (str) print (' length of str', a) # last character with the help of length of the stringprint ('str[ a]', str[ a-1]) # last character with the help of indexingprint ('str [- 1]', str [- 1]) so far, I believe you have a better understanding of "how python strings access characters". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.