py string str

1. str- escape character (/):

  print('"I\'m fine",thank you!')

2. str- sections:

  = str1 'HelloWorld'
  Print (str1 [0: +. 1. 4])
  # string from beginning to take full index 0
  Print (str1 [0:])
  # 0 starts from the default index
  print (str1 [: 4 + 1 ])
  # default starting from 0 to -1
  Print (str1 [:])

  # Take down the entire string
  Print (str1 [:: -. 1])
  # rowolleh
  Print (str1 [-3 :: -. 1])

A summary:

'' '
STR [Start: end_not: STEP]
1. Start starting point (comprising);
2. end_not ending point (not included);
3. STEP increments, if it is positive, positive taken; if it is negative reverse (taken backwards)
4. If the step is not written, the default forward one by one to get the string.
'' '

3. split()

  = STR 'Hello'
  str2 = 'World'
  # The divided character string: [ 'H', 'LLO']
  Print (str.split ( 'E'))

4. join()

  str3 = '123'
  str4 = '_'
  # 1-2-3
  print(str4.join(str3))

  str5 = ['123','456']
  # 123-456
  print(str4.join(str5))

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/dongks/p/11898949.html