In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 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.
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.