str Important Functions of Python Learning

  • 2021-12-11 18:28:50
  • OfStack

Directory 1. 6 Very Important str Processing Words 2. Important str processing can also be used in almost all data types. 1, extract characters at specific positions in strings
2. len gets several characters in the string of the current variable. 3. range creates a continuous numeric summary

1. 6 Very Important str Processing Words

1. join Add separator symbols. Other types of data may also use this

2. split partition

3. find query matches the position of sub-sequence

4. strip is removed

5. upper Capital

6. lower lowercase

7. replace Replacement

2. Important str processing is also available in almost all data types

1. Extract the characters at a specific position in the string

# Index, subscript


name = 'adam'
v = name[1]
v1 = name[2]
print(v) #d
print(v1) #a   

# Slice


name = 'adamadam'
v = name[0:3] #0<= x <3
print(v) #ada

PS: You can also get a value from the end of 1, that is to say, you can get a value from left to right and from right to left


v = ' My name is Zhang 3 Feng, I live on the loess high slope '
print (v[3:5])  #3 Abundance    # 3 <= v < 5
print (v[-3:])  # High soil slope  #-3 <= v < 0 
print (v[-3:-1]) # Soil height   #-3 <= v < -1

2. How many characters are in the string that len gets the current variable


name = 'adam'
name1 = ' Zhang 3'
v = len(name)
v1 = len(name1)    #python3 Medium   The length of Chinese is calculated by the number of words 
print(v,v1) #4 2

3. range Creates Consecutive Numbers


v = range(0, 150)       # Create 0-149 The number of (at the beginning) v Among the variables of, only 0 And 150 Two numbers) 
v1 = range(0, 150, 5)   #5 Is the step size, which is to create 0 5 10 ... 145 These figures 
v2 = range(100, 0, -1)    # From 100 To 1  Every subtraction 1 

Beginning number < = Number to output < Ending number

Summarize

This article is here, I hope to give you help, but also hope that you can pay more attention to this site more content!


Related articles: