Python (4)---string common methods

Source: Internet
Author: User

python string Common methods
password='. jpg 123456789. jpg abcdfg\n'  #the value of the string cannot be changed##strip () methodPrint(Password.strip ())#by default, whitespace and line breaks are removed on both sides of the stringPrint(Password.strip ('. jpg'))#remove the. jpg from both sidesPrint(Password.lstrip ())#drop the left space and line break of the stringPrint(Password.rstrip ())#Drop the space and line breaks to the right of the string##大小写转换Print(Password.upper ())#turn into uppercasePrint(Password.lower ())#turn into lowercasePrint(Password.capitalize ())#first letter to uppercase##替换Print(Password.replace ('123','hehe'))#ReplacePrint(Password.replace (' ',"'))#Remove all spaces in a string## start, EndFilename='A.mp3'Print(Filename.endswith ('. mp3'))#decide whether to end with XXPrint(Filename.startswith ('186'))#decide whether to start with XX##字符串分割, switch to listnames='morning Greek, Rui Han, raisin, library'Print(Names.split ())#the string into a list, if you do not specify what to split, the default is separated by a space;Print(Names.split ('.'))#If the delimiter does not exist, place the entire string as an element in the listPrint(Names.split (','))#1. Change the string to List 2, split it with an element, and divide it into a list of each element .Print(list (names))

Python (4)---string common methods

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.