Python中的join()函数的用法
函数:string.join()
Python中有join()和os.path.join()两个函数,具体作用如下:
join(): 连接字符串数组。将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串
os.path.join(): 将多个路径组合后返回
一、函数说明
1、join()函数
语法: 'sep'.join(seq)
参数说明
sep:分隔符。可以为空
seq:要连接的元素序列、字符串、元组、字典
上面的语法即:以sep作为分隔符,将seq所有的元素合并成一个新的字符串
返回值:返回一个以分隔符sep连接各个元素后生成的字符串
2、os.path.join()函数
语法: os.path.join(path1[,path2[,......]])
返回值:将多个路径组合后返回
注:第一个绝对路径之前的参数将被忽略
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#对序列进行操作(分别使用' '与':'作为分隔符) >>> seq1 = ['hello','good','boy','doiido']>>> print ' '.join(seq1)hello good boy doiido>>> print ':'.join(seq1)hello:good:boy:doiido #对字符串进行操作 >>> 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 #对元组进行操作 >>> seq3 = ('hello','good','boy','doiido')>>> print ':'.join(seq3)hello:good:boy:doiido #对字典进行操作 >>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4}>>> print ':'.join(seq4)boy:good:doiido:hello #合并目录 >>> import os>>> os.path.join('/hello/','good/boy/','doiido')'/hello/good/boy/doiido' |
Python中的join()函数的用法的更多相关文章
- Python中的join()函数的用法及列表推导式
[红色为转载后新增部分] 函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join():连接字符串数组.将字符串.元组.列表中的元 ...
- 详解Python中的join()函数的用法
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的 ...
- (转)Python中的split()函数的用法
Python中的split()函数的用法 原文:https://www.cnblogs.com/hjhsysu/p/5700347.html Python中有split()和os.path.split ...
- Python中的join()函数split()函数
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的 ...
- Python中关于join函数的陷阱?
目录 说明 数据说明 正确示例 错误示例 解决办法 说明 最近在用Python的join函数连接多个列表时,出现了如下两个错误,即合并类型不一致.折腾了很久才找到原因,真是基础不牢,地动山摇. Typ ...
- Python中的split()函数的用法
函数:split() Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(lis ...
- Python中的filter()函数的用法
转载自:脚本之家 Python内建的filter()函数用于过滤序列. 和map()类似,filter()也接收一个函数和一个序列.和map()不同的时,filter()把传入的函数依次作用于每个元素 ...
- Python中的strip()函数的用法
函数:string.strip() Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 一.函数说明 strip() 语法:str.strip([rm]); 参数说明 rm ...
- Python中numpy.apply_along_axis()函数的用法
numpy.apply_along_axis(func, axis, arr, *args, **kwargs): 必选参数:func,axis,arr.其中func是我们自定义的一个函数,函数fun ...
随机推荐
- javascript 逻辑操作符
JS按位与(&) 0001 & 0011 --- 0001 只有两个数的值为1时,才返回1 JS按位异或 (^) 0101 (expression1) 1100 (expressi ...
- 通过pustil模块取pid及对应的pidname
通过pustil模块取pid及对应的pidname import psutil import json def getpid(): reslut = psutil.pids() return resl ...
- ios枚举规范
- jquery选择器和基本语句
$("#aa"); //根据ID找 $(".aa"); //根据class找 $("div"); //根据标签名找 $("[id= ...
- 给php添加ssl证书
composer下载时报错: The "https://packagist.org/packages.json" file could not be downloaded: SSL ...
- mark asp.net mvc
http://weblogs.asp.net/scottgu/Tags/MVC http://weblogs.asp.net/scottgu/asp-net-mvc-framework-part-1 ...
- 。。。IO流学习之二。。。
fileReader的用法: import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundExc ...
- js获取元素样式
http://blog.sina.com.cn/s/blog_89cd68470101i108.html
- linux内核的makefile.txt讲解
linux内核的linux-3.6.5\Documentation\kbuild\makefiles.txt Linux Kernel Makefiles This document describe ...
- Android 开发之 ---- 底层驱动开发(一) 【转】
转自:http://blog.csdn.net/jmq_0000/article/details/7372783 版权声明:本文为博主原创文章,未经博主允许不得转载. 驱动概述 说到 Android ...