Python string-method

Source: Internet
Author: User

One
1. Upper ()
Function: Converts a character in a string to uppercase

in [+]: spamout['hello,world'in[print(Spam.upper ()) Hello,world

2.lower ()
Function: Converts a character in a string to lowercase

in [+]: spam = spam.upper () in []: spamout['hello,world'in[ Print (Spam.lower ()) Hello,world

3.isupper ()
Function: Determines whether there are uppercase characters in a string

in [+]: spamout['hello,world'in[]: spam.isupper () out[ all]: True

4.islower ()
Function: Determine if there are lowercase characters in the string

in [+]: spamout['hello,world'in[]: Spam.islower () out[25] : False

5.isalpha ()
Isalpha () returns True if the string contains only letters and is not empty

in [+]: spamout['hello,world'in[]: Spam.isalpha () out[ (): False

6.isalnum ()
Isalnum () returns True if the string contains only letters and numbers and is not empty

' 123hello ' In [Max]: Mystring01.isalnum () out[]: True

7.isdecimal ()
Isdecimal () returns True if the string contains only numeric characters and is not empty

' 123456 ' In [the]: Mystring01.isdecimal () out[]: True

8.isspace ()
Isspace () returns True if the string contains only spaces, tabs, and line breaks, and is not empty

"in[si]: mystring01.isspace () out[]: True

9.istitle ()
Istitle () returns True if the string contains only words with uppercase letters that are followed by lowercase letters

' Helloworld ' In [[]: Mystring01.istitle () out[]: True

10.startswith ()
The StartsWith () method returns True if the string they are calling starts with the string passed in by the method

' Hello World '. StartsWith ('hello') out[]: True

11.endswith ()
The EndsWith () method returns True if the string they are invoking ends with the string passed in by the method

' Hello World '. EndsWith ('ld') out[]: True

12.join ()
Splicing String list

' - '. Join (['aaa', 'bbb','CCC ' ]) out['aaa-bbb-ccc'

13.split ()
Explode string

' AAA-BBB-CCC '. Split ("-") out[]: ['aaa' BBB ' ' CCC ']

14.strip ()
(1) Delete blank characters on both sides

Print (mystring01)  Hel Lo, w o r ldin [print(Mystring01.strip ()) Hel Lo, w o r ld

(2) Delete the specified string

Print (mystring01)  Hel Lo, w o r ldin [print(Mystring01.strip ('  hel lo' ) )), W o r ld

15.lstrip ()
Remove left white space character

Print (mystring01)  Hel Lo, w o r ldin [print(Mystring01.lstrip ()) Hel Lo, w o r ld

16.rstrip ()
Delete Right white space character

Print (mystring01)  Hel Lo, w o r ldin [print(Mystring01.rstrip ())  Hel Lo, w o r ld

17.pyperclip Module
Using the Pyperclip module's total copy and paste parameters

Import pyperclippyperclip.copy ('Hello world! ' ) Pyperclip.paste ()





Python string-method

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.