The use of the Join () function in Python

Source: Internet
Author: User

Function: String.Join ()

Python has join () and Os.path.join () two functions, which work as follows:
Join (): An array of connection strings. Generates a new string from a string, tuple, or element in the list, with the specified character (delimiter) connection
Os.path.join (): Combine multiple paths to return

First, function description
1. Join () function

Syntax: ' Sep '. Join (SEQ)

Parameter description
Sep: Delimiter. Can be empty
SEQ: sequence of elements to concatenate, strings, tuples, dictionaries
The syntax above is to combine all the SEQ elements into a new string with Sep as a delimiter

Return value: Returns a string that is generated after each element is concatenated with the delimiter Sep

2. Os.path.join () function

Syntax: Os.path.join (path1[,path2[,......])

Return value: Combine multiple paths to return

Note: Parameters before the first absolute path are ignored

1#对序列进行操作 (respectively, use' 'And':'as a delimiter)2   3>>> seq1 = ['Hello','Good',' Boy','Doiido']4>>> Print' '. Join (SEQ1)5 Hello good boy doiido6>>> Print':'. Join (SEQ1)7 Hello:good:boy:doiido8   9   Ten #对字符串进行操作 One    A>>> SEQ2 ="Hello good boy doiido" ->>> Print':'. Join (SEQ2) - h:e:l:l:o:: g:o:o:d:: b:o:y::d: O:i:i:d:o the    -    - #对元组进行操作 -    +>>> seq3 = ('Hello','Good',' Boy','Doiido') ->>> Print':'. Join (SEQ3) + Hello:good:boy:doiido A    at    - #对字典进行操作 -    ->>> Seq4 = {'Hello':1,'Good':2,' Boy':3,'Doiido':4} ->>> Print':'. Join (SEQ4) - Boy:good:doiido:hello in    -    to #合并目录 +    ->>>Import OS the>>> Os.path.join ('/hello/','good/boy/','Doiido') * '/hello/good/boy/doiido'

Excerpt from blog: https://www.cnblogs.com/jsplyy/p/5634640.html

The use of the Join () function in Python

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.