Long string
" " ---------userinfo---------- name:lalalaxpf age:18 sex:man iphone:123 Address:ooxx -----------End-------------- " " Print (str) ---------userinfo---------- name:lalalaxpf age : sex:man iphone:123 Address:ooxx -----------End--------------
Raw string
Special meaning of the cancellation character
Print ('oo\nxx') Ooxx Print (R'oo\nxx') oo\nxx
string concatenation
1. Connect via +
Print ('oo'+'xx') Ooxx
2. Join () method
>>> list = ['a','b']'. Join ( List)'ab'
String slicing, intercepting
Grammar
Str[start:end:step]
String Common methods
Str.strip ()
# remove spaces and line breaks, not in the middle ' \noo \nxx\n '>>> str.strip ()'oo \nxx '
# Remove the specified string ' Ooxx '>>> str.strip ('xx')'oo '
Str.lstrip (), Str.rstrip ()
' Ooxx '>>> str.lstrip ()# Remove the left space and line break 'Ooxx '>>> str.rstrip ()# Remove the space on the right and line break ' Ooxx '
Str.count ()
# find the number of occurrences of a character in a string ' Ooxx '>>> str.count ('o')2
Str.capitalize ()
# Capitalize first letter ' Ooxx '>>> str.capitalize ()'ooxx'
Str.title ()
# all words start with uppercase, and the remaining letters are lowercase ' Hello World '>>> str.title ()'HelloWorld'
python--string