Python Road--str Type

Source: Internet
Author: User
Tags function prototype

functions defined within the STR type
  • Capitalize: Capitalize the first letter, the remaining lowercase

    Function prototype: def capitalize (self)

    Usage:

    Str1.capitalize ()

  • Casefold: Change All lowercase

    Function prototype: def casefold (self)

    Usage:

    Str1.casefold ()

  • Center: Content Centered

    Function prototypes: Def center (self, width, fillchar=none)

    Usage:

    Str1.center (N,fill) #n表示总长度, fill indicates a filling symbol

  • Count: Count the number of sub-sequences

    Function prototypes: def count (self, sub, Start=none, End=none)

    Usage:

    Str1.count (sub,m,n) Number of statistics sub in the #在 [m,n) interval

  • Encode: encoding, for Unicode

    Function prototypes: Def encode (self, encoding= ' utf-8 ', errors= ' strict ')

  • Endswitch: Determines whether to end with suffix, returns false or True

    Function prototypes: Def endswith (self, suffix, start=none, end=none) Usage:

    Str1.endswith ("suffix", m,n) #在 [m,n) interval to find out whether to end with suffix

  • StartsWith: Determines whether to start with suffix, returns false or True

    Function prototypes: Def startswith (self, prefix, start=none, end=none) Usage:

    Str1.endswith ("prefix", m,n) #在 [m,n] interval to find out whether to start with prefix

  • Expandtabs: Convert tab to space, default one tab to 8 spaces

    Function prototypes: Def expandtabs (self, tabsize=8)

    Usage:

    Str1.expandtabs ()

  • Find: Find sub-sequence position, if not found, return-1

    Function prototypes: Def find (self, sub, Start=none, End=none)

    Usage:

    Str1.find (sub,m,n) #查找sub的位置并返回开始的值

  • Format: string formatting, dynamic parameters

    Function prototypes: def format (self, *args, **kwargs) Usage:

    str1= "Hello {0}, hello {1}"

    Str1.format ("World", "Python")

  • Index: Sub-sequence position, if not found, error

    Function prototypes: Def index (self, sub, Start=none, End=none)

    Usage:

    Str1.index (Sub,m,n)

  • Isalnum: Whether it is a letter or a number

    Function prototype: def isalnum (self)

  • Isalpha: Whether it is a letter

    Function prototype: def isalpha (self)

  • IsDigit: Whether it is a number

    Function prototype: def isdigit (self)

  • Islower: Lowercase

    Function prototype: def islower (self)

  • Isspace: Detects whether a string consists of only spaces.

    Function prototype: def isspace (self)

  • Istitle: Checks if all the words in the string are spelled with uppercase letters and the other letters are lowercase.

    Function prototype: def istitle (self)

  • Isupper: Deciding whether to capitalize

    Function prototype: def isupper (self)

  • Join: Connect

    Function prototypes: Def join (self, iterable)

    Usage:

    "Fill". Join (STR1) #用fill符号连接str1之间的字符

    For example:

    str1= "12345"

    "+". Join (STR1)

    Input as 1+2+3+4+5

  • Ljust: Content left aligned, right filled with Fillchar

    Function prototypes: Def ljust (self, width, fillchar=none)

    Usage:

    Str1.ljust (M,fill) #m表示长度, fill represents the filled character

  • Lower: Variable lowercase

    Function prototype: def lower (self)

    Usage:

    Str1.lower ()

  • Upper: Variable Capitalization

    Function prototype: Def UPPER (self)

    Usage:

    Str1.upper ()

  • Strip: Remove chars on both sides, default to Spaces

    Function prototypes: def strip (self, Chars=none)

    Usage:

    Str1.strip ("chars") #chars表示要移除的字符串

  • Partition: Split into front and bottom three (left to right) with one rpartition right-to-left

    Function prototypes: Def partition (self, SEP)

    Usage: str1.partition (Sep) # Sep becomes part of Sep before and after it becomes a part

  • Replace: Replacing

    Function prototypes: def replace (self, old, new, Count=none)

    Usage: str1.replace (sub1,sub2,n) #将sub1替换为sub2, replace n times, default replace All

  • Split: Split, maxsplit up to several times

    Function prototypes: Def split (self, sep=none, maxsplit=-1)

    Usage:

    Str1.split (sep,m) # according to Sep division m times, without m words, have Sep split

  • Splitlines: separated by rows (' \ r ', ' \ r \ n ', \ n '), returns a list containing the rows as elements, if the argument keepends is False, does not contain a newline character, and if true, the newline character is preserved.

    Function prototypes: Def splitlines (self, keepends=none)

    Usage: str1.splitlines ()

  • Swapcase: Case Interchange

    Function prototype: def swapcase (self)

  • Title: Change a string to a word beginning with uppercase, the other lowercase

    Function prototype: def title (self)

  • Translate: conversion, you need to make a corresponding table, the last one represents the deletion of the character set

    Function prototypes: Def translate (self, table)

    Usage:

    Str1.translate (Trantab), but you need to use Maketrans first

    For example:

    "aeiou"outtab = "12345"trantab = temp.maketrans(intab, outtab)str = "this is string example....wow!!!"print(str.translate(trantab))#输出结果th3s 3s str3ng 2x1mpl2....w4w!!!

Python Road--str Type

Related Article

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.