Python string Manipulation Methods Daquan

Source: Internet
Author: User


1. Remove Space

Strip (self, Chars=none)

Lstrip (self, chars=none)

Rstrip (self, chars=none)


2. Uppercase and lowercase conversions in strings

Convert lower (self) to lowercase

Convert upper (self) to uppercase

Swapcase (self) case-sensitive interchange

Capitalize (self) Capitalize first letter

Capitalize (self) first letter converted to uppercase, remaining lowercase

Title (self) The first letter of the word is converted to uppercase


3. Find string

Find (self, sub, Start=none, End=none) finds string position, cannot find return-1

Index (self, sub, start=none, End=none) Find string position, error not found

RFind (self, sub, start=none, End=none) find from the right

Count (self, sub, Start=none, End=none) How many of the specified characters are searched



4. String alignment

Rjust (self, width, fillchar=none) Take fixed length right alignment, left not enough space to complement

Ljust (self, width, fillchar=none) take fixed length left aligned, right not enough space to complement

Center (self, width, fillchar=none) Take fixed length middle alignment, left or right not enough space to complement


5. String judgment

Whether the Isupper (self) string is all uppercase

Islower (self) string is all lowercase

StartsWith (self, prefix, Start=none, End=none) whether a string begins

EndsWith (self, suffix, start=none, end=none) whether a string has ended

Whether the isalnum (self) is all letters or numbers

Whether the isalpha (self) is full letter

Whether the isdigit (self) is a full number


6. String segmentation

Split (self, sep=none, Maxsplit=none) separated by a symbol, default space


7. String connection

Join (self, iterable) connect a tuple or list

>>>var_list = [' Tom ', ' David ', ' John ']

>>>a = ' _ '

>>>print A.join (var_list)

>>>tom_david_john


8, the TAB key fills the space, the tab is denoted by \ t

Expandtabs (self, tabsize=none) Tab key fills a specified number of spaces


9. String substitution

Format (self, *args, **kwargs) replaces placeholder {0} {1} ...

Replace (self, old, new, Count=none) replaces the specified number of old to new, starting from the left


This article is from the "10893237" blog, please be sure to keep this source http://10903237.blog.51cto.com/10893237/1973881

Python string manipulation methods Daquan

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.