Python's partition () method

Source: Internet
Author: User

Describe

The partition () method is used to split the string according to the specified delimiter.

If the string contains the specified delimiter, a tuple of $3 is returned, the first one is the substring to the left of the delimiter, the second is the delimiter itself, and the third is the substring to the right of the delimiter.

The partition () method was added in version 2.5.

Grammar

Partition () method syntax:

Str.partition (str)
Parameters

STR: the specified delimiter.

return value

Returns a tuple of $3, the first is the substring to the left of the delimiter, the second is the delimiter itself, and the third is a substring to the right of the delimiter.

Instance

The following example shows the use of the partition () method:

# !/usr/bin/python  "http://www.w3cschool.cc/"print str.partition (":// ")

The output is:

('http'://'  www.w3cschool.cc/')

Python's partition () 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.