Python string manipulation

**The definition of strings in Python: Strings are immutable sequences of Unicode code points. **

Python built-in functions provide a powerful way to use strings, master common methods, and are very useful for data processing, interviews, and written examinations.

dir(str)['__add__','__class__','__contains__','__delattr__','__dir__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__','__getnewargs__','__gt__','__hash__','__init__','__init_subclass__','__iter__','__le__','__len__','__lt__','__mod__','__mul__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__rmod__','__rmul__','__setattr__','__sizeof__','__str__','__subclasshook__','capitalize','casefold', 'cent
er', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isuppe
r', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfi
ll']

**First of all, a string is a sequence, so it supports slicing and indexing operations. For details, please refer to this article Detailed Explanation of Python Basic Data Types. **

**The following is a summary of common built-in functions: **

s="hello testers !"print(s.replace('hello','hi')) #Output hi testers!

s="hello testers !"print(s.split()) #Output['hello','testers','!']print(s.partition('testers')) #Output('hello ','testers',' !')

s=" hellotesters! "print(s.strip()) #Output hellotesters!print(s.rstrip()) #Output hellotesters!print(s.lstrip()) #Output hellotesters!

s1="hellotesters!"
s2="HELLO TESTERS!"
s3="Hello Testers!"
s4=s1="hello testers!"print(s1.upper()) #Output HELLO TESTERS!print(s2.lower()) #Output hello testers!print(s3.swapcase()) #Output hELLO tESTERS!print(s1.capitalize()) #Output Hello testers!print(s4.title()) #Output Hello Testers!

s1="hello testers!"print(s1.count('l')) #Output 2print(s1.find('hello')) #Output 0print(s1.rfind('testers!')) #Output 6

s1="hellotesters!1234567890"
s2="hellotesters"
s3="1234567890"
s4="HELLOTESTERS"print(s1.isalnum()) #Output False
print(s2.isalpha()) #Output True
print(s3.isdigit()) #Output True
print(s4.isupper()) #Output True
print(s2.islower()) #Output True

Recommended Posts

Python string manipulation
Python string
Python string
Str string in Python
How Python converts string case
Python interview questions: string concatenation
Python string three formatted output
Python implements string and number splicing
The premise of Python string pooling
Python classic programming questions: string replacement
Python multithreading
Python CookBook
Python FAQ
Python3 dictionary
Python3 module
python (you-get)
Python basics
Python string to judge the password strength
Python descriptor
Python basics 2
Python exec
Python notes
Python3 tuple
CentOS + Python3.6+
Python advanced (1)
Python decorator
Python IO
Python multithreading
Python toolchain
Python3 list
Python multitasking-coroutine
Python overview
python introduction
Python analytic
Python basics
07. Python3 functions
Python basics 3
Python multitasking-threads
Python functions
python sys.stdout
python operator
Python entry-3
Centos 7.5 python3.6
python queue Queue
Python basics 4
Python basics 5