What are the common skills of python string
This article mainly introduces python string commonly used skills, the text is very detailed, has a certain reference value, interested friends must read!
1. string[a: b] intercepts the a-th to b-th characters of the string.
For convenience of description, unless otherwise specified, the nth number mentioned in this sentence is counted from 0 (i.e., the first is the second of normal human thoughts).
a = "AaBbCcDd"print(a[1: 5])print(a[2: -2])
2. for s in string Traverses the characters of a string.
for s in "AaBbCcDd": print(s)
3. String[::-1] inverts the string.
a = "AaBbCcDd"print(a[::-1])
4. String.split is divided by string2.
Split only the interger string2 and previous strings, the rest as the last item in the list. Returns a list (string2 cannot be empty).
string2 is a space by default (" ") integer by default divides all string2.
a = "AaBaCaDa"print(a.split("a", 2)) The above is "What are the common skills of python strings?" All the contents of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!