Python String Operation Basics
First of all,python strings can not be changed,because they are immutable.[*]String escape
'Isn\'t,he said'
"Isn\"t,he said"
[*]more readable string
print("Isn\"t,he said")
[*]do not want to escape
print(r'C:some\name')
[*] String concatenating
"py" + "pyon"
"py" "pyon" #works
prefix="py"
prefix "thon" #does't work
3 * "un" "beat" #does't work
prefix + (3 * "un") #works
[*] String indexing
word="python"
word #'p'
word[-1] #'n'
[*] String slicing
word="python"
word #'py'
[*] String length
the build-in function len() returns the length of a string.
页:
[1]