Split & Combine #拆分和组合
#split () slices a string by specifying a delimiterLAN ="python Ruby c C + + Swift"lan.split () ['python','Ruby','C','C + +','Swift']todos="download python, install, download IDE, learn"Todos.split (', ')['Download Python','Install','Download IDE','Learn']','. Join (['Download Python','Install','Download IDE','Learn'])'Download Python,install,download Ide,learn'
Substitue #替换
#replace ()s ='I like C. I like C + +. I like Python'S.replace (' like','Hate')'I hate C. I hate C + +. I Hate Python'S.replace (' like','Hate', 1)'I hate C. I like C + +. I like Python'
Layout #布局
align ='learn how to align'Align.center (30)'learn how to align'Align.ljust (30)'learn how to align'Align.rjust (30)'learn how to align'ralign= Align.rjust (30) Ralign.strip ()'learn how to align'
Other useful tools
Py_desc ="Python Description:python is a programming language so lets you work quickly and integrate systems more effectively ."Py_desc.startswith ('Python') Truepy_desc.endswith ('effectively.') Truepy_desc.find ('language')44Py_desc.isalnum () Falsepy_desc.count ("Python")2Py_desc.strip ('.')'Python Description:python is a programming language so lets you work quickly and integrate systems more effectively 'Py_desc.upper ()'PYTHON Description:python is A programming LANGUAGE so LETS you work QUICKLY and integrate SYSTEMS more effectively .'Py_desc.title ()'Python Description:python is A programming Language so Lets you work Quickly and integrate Systems more effectively .'
New Style in Python 3.6
Print('%s%s'% (' One',' Both'))Print('{} {}'. Format (' One',' Both'))Print('%d%d'% (1, 2))Print('{} {}'. Format (1, 2)) One twoone1 21 2Print('{1} {0}'. Format (' One',' Both')) The Onea= 5b= 10Print(f'Five plus Ten is {a + B} and not {2 * (A + b)}.') Five plus ten is15 and not30. Name="Joshua"question="Hello"Print(f"Hello, {name}! How ' s It {question}?") Hello, joshua! How's It hello?
Python: String handler function