Pycharm Basic Syntax - String

Defining strings
You can use "" or '' to put strings into them.
insert image description here
Input and output formats
Input input ("input content")
output print ("results that need to be output") insert image description here
Slice
Slice: refers to intercepting a part of the object of the operation The operation of (applicable to strings, lists, tuples) [start subscript: end: step]
The index in the string is 0-based, the index of the last element is -1
The selected interval starts from " Start, to the end of the previous bit of the "end" bit (excluding the end bit itself, the step size indicates the selection interval) to
extract the first three charactersinsert image description here

Get the value of the corresponding
insert image description here
index, extract all characters ,
insert image description here
insert image description here
take every other character, take one character
insert image description here
from right to left, and take one character
insert image description here
string operation
find keyword to check whether the character is included in the string, if it returns the starting index value, then Returns
a string in -1 format.find(str,start=0,end=len(mystr))
insert image description here
number of queries: count()
insert image description here
replaces
insert image description here
the split
Take str as the split slice mystr, if maxsplit has a specified value, only separate maxsplit strings
Format my——str.split (str=" ", 2)
insert image description here
remove the spaces at both ends
Remove the strings on both sides: **strip()** delete the blank characters at both ends of the mystr string
insert image description here
startswith() starts with what startswith() checks Whether the string starts with
insert image description here
str Return true if not return false Uppercase find() function adds a value to a string
insert image description here

insert image description here

insert image description here
insert image description here
insert image description here

insert image description here

insert image description here

insert image description here
insert image description here
insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44826661/article/details/124050478