Python string manipulation function two

Source: Internet
Author: User

#-*-coding:utf-8-*- Line="l want watch movie with you."Print(Line.center (50))Print(Line.ljust (50))Print(Line.rjust (50))#Center string Centered#Ljust String Left#rjust characters in the right#Lstrip Remove whitespace characters to the left of a string#Rstrip Remove whitespace characters to the right of a string#strip delete whitespace characters at both ends of a stringWord="\ t \ I am a bird. \ r \ n"Print("==lstrip==")Print(Word.lstrip ())Print("===rstrip==")Print(Word.rstrip ())Print("==strip==")Print(Word.strip ())#whitespace characters include invisible characters such as spaces/n/tNword="Hello this a new world."Print("==partition==")#PartitionPrint(Nword.partition ("a"))#finds the specified string from left to right in the source string, finds the specified string to be cut, divides it into 3 parts, specifies the string before, and, after itself, the return value is a tuple#if the specified string does not exist in the source string, the result consists of the source string itself, which consists of two empty strings#rpartition to find the specified string from right to leftWline="hello \ n World"Print("==splitlines==")Print(Wline.splitlines ())#splitlines the row to return a list containing the rows as elementsPrint("==isalpha==")Print(Wline.isalpha ())#returns false because there are spaces, escape characters#Isalpha Determines whether all characters in a string are letters, the letter returns True, and the other returns falseNum="12233"Print("==isdigit==")Print(Num.isdigit ())#IsDigit Determines whether all characters in a string are numbers, returns True, and returns falseStr="sadfa213"Print("==isalnum==")Print(Str.isalnum ())#Isalnum Whether the string is only composed of numbers and letters, returns True, and the other returns falseSpace="  "Print("==isspace==")Print(Space.isspace ())#Isspace Determines if there are only spaces in the string, returns True, and returns falsePrint("==join==") Tstr="_"List1= ["AA","BB"]Print(Tstr.join (list1))#inserts the specified character after each character, forming a new string

Python string manipulation function two

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.