Python STR Internal Function-Personal class notes, after-school summary

Source: Internet
Author: User

View the internal STR functionality, which can be viewed in the same way as int, or by using Type (str), dir (str).

1. Capitalize: Capitalize first letter

S.capitalize (), string

" Parr "  = str1.capitalize ()print(result)# returns Parr
View Code

2. Center (self, Width, fillchar=none): Content centered, Width: total length; Fillchar: padding content in white space (default none)

S.center (width[, Fillchar]), string

" Parr "  = Str1.center ("*")print(result)# back to ***parr***
View Code

3, COUNT (self, sub, Start=none, End=none): Number of substrings of STR, case-sensitive

S.count (sub[, start[, end]), int

" parrabcadb "  = Str1.count ("a")print(result)#  Returns 2, indicating that two A is found
View Code

4, decode (self, Encoding=none, Errors=none): Decoding

S.decode ([encoding[,errors]]), object

" haha "  == result.decode ()Print (str2) screen printing: haha
View Code

5, Encode (self, Encoding=none, Errors=none): coded

S.encode ([encoding[,errors]]), object

" haha "  = str1.encode ()print(result)# returns B ' \xe5\x93\x88\xe5\ X93\x88 '
View Code

6, endswith (self, suffix, start=none, end=none): No end with XX, return value of bool type

S.endswith (suffix[, start[, end]), BOOL

" Parr Luck "  = Str1.endswith ("")print(result)#  screen printing ture
View Code

7, Expandtabs (Self, tabsize=none): The tab is converted to a space, the default is a tab eight spaces

S.expandtabs ([Tabsize]), string

" Parr\thello "  = str1.expandtabs ()Print (Result) screen printing: Parr    Hello
View Code

8, find (self, sub, Start=none, End=none): Find the sub-sequence position, if not found return-1

S.find (Sub [, Start [, end]]) int

" Parr "  = str1.find ('a')print(result)#  Screen printing 1, indicating a at 1 position
View Code

9, Isalnum (self): whether it is a letter or a number, returns the value of type bool

S.isalnum (), BOOL

" parr2017 "  = str1.isalnum ()print(result)# screen printing: Ture
View Code

10, Isalpha (self):: Whether it is a letter

S.isalpha (), BOOL

" Parr "  = str1.isalpha ()print(result)# screen printing: Ture
View Code

11, IsNumeric (self): Whether it is a number

S.isnumeric (), BOOL

"  . "  = str1.isnumeric ()print(result)# screen printing ture
View Code

12. Islower (self): lowercase

Isupper (self):: Whether it is uppercase

S.islower (), BOOL

" Parr "  = str1.islower ()print(result)# returns ture" Parr "  = str1.isupper ()print(result)# returns false
View Code

13. Replace (self, old, new, Count=none): Replace content

S.replace (old, new[, Count]), string

" Parr "  = str1.replace ('a','hello')Print  (Result)# screen printing: Phellorr
View Code

14, Split (self, Sep=none, Maxsplit=none): Split content, maxsplit up to a few times, return a list

S.split ([Sep [, Maxsplit]]), List of strings

" Parr "  = str1.split ('a')print(result)#  return [' P ', ' RR ']
View Code

15. Splitlines (Self, Keepends=false):: Returns a list based on line break

S.splitlines (keepends=false), List of strings

""" Parr        Hello        everyone"" "= str1.splitlines ()print(result)  # return [' Parr ', '        hello ', '        everyone ']
View Code

16, StartsWith (self, prefix, Start=none, End=none): whether to start with content in prefix

S.startswith (prefix[, start[, end]), BOOL

""" Parr        Hello        everyone"" "= Str1.startswith ('Parr' ) )print(result)# returns ture
View Code

17, Strip (Self, Chars=none): Remove both ends of the blank

S.strip ([chars]), string or Unicode

"             parr2017              "= str1.strip ()print(result)# back to parr2017
View Code

18, __contains__ (self, y): Check if y is included in X

X.__contains__ (y) <==> y in X

View Code

Python STR Internal Function-Personal class notes, after-school summary

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.