Catalog
1、 The string “atom” All capitalized
2、 Split string , Make the string “Atom_is_good” Divided into 3 A string “Atom”、“is”、“good”
3、 String concatenation , send ['Atom', 'is', 'good'] Splice into Atom_is_good
4、 Replace string , hold “Atom is good” Replace with “Everybody is good”
5、 Count the number of string occurrences , Statistics "Atom is good" in “o” Number of occurrences
6、 Determine whether the string exists , Judge “m” Whether it exists in the string “Atom” in
Use built-in functions upper()
a = "atom" # Defining variables a For the string atom
print(a.upper()) # Using functions upper() hold atom All capitalized The result is :ATOM
Use built-in functions split() ( stay () Fill in the symbols that need to be divided )
b = "Atom_is_good" # Define a variable b For the string "Atom_is_good"
print(b.split("_")) # Use built-in functions split() Segmentation
Use built-in functions join() Splicing (" Fill in the content to be spliced here ".join( Iteratable objects to splice ))
c= ['Atom', 'is', 'good'] # Define a variable c by ['Atom', 'is', 'good']
print("_".join(c)) # Use .join Function The result is :Atom_is_good
Use built-in functions replace() Replace (replace( Original value , Value to change to ))
d = "Atom is good" # Define a variable d For the string "Atom is good"
print(d.replace("Atom","Everybody")) # Use replace() Function to replace The result is :Everybody is good
Use built-in functions count() Make statistics (count( String to count the number ))
e = "Atom is good" # Define a variable e by "Atom is good"
print(e.count("o")) # Use built-in functions count() Make statistics The result is :3
There are two ways 1 It's using in Direct judgment
f = "Atom" # Define a variable f For the string “Atom”
print("m" in f) # Use in Judge m Whether it exists in the string f in The result is :Ture
You can also use functions find(), The subscript corresponding to the string will be given , If not, the return value is -1(find( String to find ))
f = "Atom" # Define a variable f For the string "Atom"
print(f.find("m")) # Use built-in functions find() Judge The result is :3
The official account is two-dimensional code. , The content is sent out synchronously , We can focus on learning together
This is the official account of Zhang Gouzi's brother brother. , Will share some of the usual work experience , You can pay attention to .