Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common skills of python string

Shulou Source: shulou.com Published: 2022-06-03 15:33:59 10月01日 Update

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!

Tags: Characters strings commonly used skills content articles humans values interests guys buddies ideas what they say more knowledge empty characters spaces industries sentences information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology vpn NVidia MySQL