Python Join and split usage

Source: Internet
Author: User

Using the Python join and split methods, join is used to concatenate strings, split exactly the opposite, splitting the strings.

Strip () for removing the character specified at the beginning of the end, empty is to remove the white space character \t,\n,\r meaning

1.join Usage Example >>>li = [' My ', ' name ', ' is ', ' Bob '] >>> '. Join (LI) #用空格把列表连接起来, so it's a string. ' My name is Bob ' >>> ' _ '. Join (LI) ' my_name_is_bob ' >>> s = [' my ', ' name ', ' is ', ' Bob '] >>> ". Join (s) ' My name is Bob ' >>> '. Join (s) ' my '. Name: Is.. Bob ' 2.split Usage example >>> b = ' my '. Name: Is.. Bob ' >>> b.split () [' My.. Name: Is.. Bob '] >>> b.split ("..") [' My ', ' name ', ' is ', ' Bob '] >>> b.split ("..", 0) [' my '. Name: Is.. Bob '] >>> b.split ("..", 1) [' My ', ' name '. Is.. Bob '] >>> b.split ("..", 2) [' My ', ' name ', ' is '. Bob '] >>> b.split ("..", -1) [' My ', ' name ', ' is ', ' Bob '] can see that b.split ("..",-1) is equivalent to B.split ("..")

Python Join and split usage

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.