Python notes (9): String operations, python notes

Source: Internet
Author: User
Tags uppercase character

Python notes (9): String operations, python notes

(1)String

Single quotation marks, double quotation marks, and triple quotation marks can all be used as the start and end of a string, and double quotation marks can be used to directly input multiple lines of strings. The triple quotation marks are generally used to write comments for multiple rows.

 

(2)RAnd \

RConverts a string to the original string, ignoring all escape characters.

\Is an escape character.

(3)String subscript and slice

 

(4)String in and not in

 

(5)Change case sensitivity

 

Method

Description

Upper ()

Convert all letters to uppercase (a new string is returned, and the original string will not be changed)

Lower ()

Convert all letters to lowercase letters (a new string is returned, and the original string will not be changed)

 

(6)IsxString Method

Method

Description

Isupper ()

Returns TRUE if all characters in the string are uppercase; otherwise, FALSE.

Islower ()

Returns TRUE if all characters in the string are in lowercase. Otherwise, FALSE is returned.

Isalpha ()

Returns true if the string contains only letters and is not empty; otherwise, returns false.

 

Isalnum ()

Returns true if the string contains only letters and numbers and is not empty; otherwise, returns false.

 

Isdecimal ()

Returns true if the string contains only numbers and is not null. Otherwise, returns false.

 

Isspace ()

If the string contains only spaces, tabs, and line breaks, and is not empty, true is returned. Otherwise, false is returned.

 

Istitle ()

Returns true if the string contains only the words starting with an uppercase character and followed by lowercase letters and is not empty. Otherwise, false is returned.

 

 

(7)Startswith ()And endswith ()

Method

Description

Startswith ()

Returns true if it starts with the specified string. Otherwise, returns false.

Endswith ()

Returns true if it ends with a specified string. Otherwise, false is returned.

 

(8)Join ()And split ()

Method

Description

Join ()

Concatenates strings in the list to form a separate string

Split ()

Returns a list of strings separated by spaces by default. You can also specify parameters. For example, in ps. split (':', 1), the first parameter is separated by:, and the second parameter is the maximum number of splits. By default, the parameter is split as much as possible.

 

(9)Strip (), Lstrip (), rstrip ()

Method

Description

Strip ()

Removes spaces, tabs, and line breaks from the left and right sides)

Lstrip ()

Delete blank characters (spaces, tabs, and line breaks) on the left)

Rstrip ()

Delete blank characters (spaces, tabs, and line breaks) on the Right)

 

(10)PyperclipModule

Pip install pyperclip

1 import pyperclip2 3 # copy data to clipboard 4 pyperclip. copy ('Hello word') 5 # paste clipboard content 6 print (pyperclip. paste ())

 

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.