Python Learning notes (10)

Source: Internet
Author: User

String method


find join lower replace split strip translate


Find

You can find the string in a longer string, the return value is the leftmost index of the location where the string is located, and cannot find the return-1

Cases:

>>> ' with a Moo-moo here,and a moo-moo there '. Find (' moo ')

7

>>> ' with a Moo-moo here,and a moo-moo there '. Find (' Hello ')

-1


Join

The element in the connecting sequence is the inverse method of Split

Cases:

>>>sss = [' 1 ', ' 2 ', ' 3 '] #注意: This must be quoted, because it can only concatenate strings

>>>CCC = ' + '

>>>ccc.join (SSS)

' 1+2+3 '


>>>dirs = ', ' usr ', ' bin ', ' env '

>>> '/'. Join (dirs)

'/usr/bin/env '

>>> print ' C: ' + ' \ \ '. Join (dirs)

C:\usr\bin\env


Lower

Returns the lowercase letter version of the character

Cases:

>>> ' Where is You '. Lower ()

' Where is You '


Replace

The resulting string after all occurrences of a string have been replaced

Cases:

>>> ' This was a test '. Replace (' is ', ' EEZ ')

' Theez eez a test '


Split

Splitting a string into a sequence , the inverse method of the Join method

Cases:

>>> ' 1+2+3+4 '. Split (' + ') #此处若不指定任何分割符 with a space separator (space, tab, line wrap, etc.)

[' 1 ', ' 2 ', ' 3 ', ' 4 ']


Strip

Returns a string that strips both sides of the space (excluding interior)

Cases:

>>> ' where is You '. Strip ()

' Where is You '

>>> ' ***where * is * you *********! '. Strip (*!)

' WHERE * is * you '


Translate

Replace Some parts of a string, handling only a single character


This article is from the "Ride a Pig to Travel" blog, please be sure to keep this source http://songqinglong.blog.51cto.com/7591177/1712599

Python Learning notes (10)

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.