Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of having join () and os.path.join () functions in Python

Shulou Source: shulou.com Published: 2022-06-01 02:56:05 10月03日 Update

This article mainly shows you "Python has join() and os.path.join() two functions what is the use of", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "Python has join() and os.path.join() two functions what is the use of" this article bar.

Python has join() and os. path. join() functions, which do the following:

join(): join string arrays. concatenates elements in a string, tuple, or list with a specified character (delimiter) to generate a new string

os.path.join(): Return after combining multiple paths

Operates on sequences (using ' ' and ':' as delimiters, respectively)

>>> seq1 = ['hello','good','boy','doiido']>>> print ' '.join(seq1)hello good boy doiido>>> print ':'.join(seq1)hello:good:boy:doiido

Manipulate on strings

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

Manipulate on tuples

>>> seq3 = ('hello','good','boy','doiido')>>> print ':'.join(seq3)hello:good:boy:doiido

operating on dictionaries.

>>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4}>>> print ':'.join(seq4)boy:good:doiido:hello

merged directory

>>> import os>> os.path.join ('/hello/','good/boy/',' doido')'/hello/good/boy/doido')'/hello/good/boy/doido', above is "Python has join() and os.path.join() two functions have what to use" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Characters two functions strings content articles delimiters learning help functions elements multiple dictionaries sequences arrays easy to understand more organization directories knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Linux Shulou Tech Info Huawei