Example of join and split usages in Python

Source: Internet
Author: User
Join is used to concatenate strings, split exactly the opposite, splitting strings.
No need to explain, after reading the code, it is self-existing.
Copy the Code code as follows:


>>>li = [' My ', ' name ', ' is ', ' Bob ']
>>> ". Join (LI)
' My name is Bob '
>>>s = ' _ '. Join (LI)
>>>s
' My_name_is_bob '
>>>s.split ('_')
[' My ', ' name ', ' is ', ' Bob ']

The English version of the join and split is explained below:

Join (...)
S.join (sequence), string

Return a string which is the concatenation of the strings in the
Sequence. The separator between elements is S.

Split (...)
S.split ([Sep [, Maxsplit]]), List of strings

Return A list of the words in the string S, using Sep as the
Delimiter string. If Maxsplit is given, at the most maxsplit
Splits is done. If Sep is no specified or is None and any
Whitespace string is a separator and empty strings be removed
From the result.

  • 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.