Python: String handler function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.