博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python字符串| join()方法与示例
阅读量:2530 次
发布时间:2019-05-11

本文共 1256 字,大约阅读时间需要 4 分钟。

join() is an in-built method in Python and it is used to join elements of the list, string etc with the given str separator.

join()是Python中的一种内置方法,用于通过给定的str分隔符连接列表,字符串等元素。

Note: Method is called with the separator and as arguments elements are provided, then the final (returned) string is a joined string by the separator string.

注意:方法是使用分隔符调用的,并提供了arguments元素,然后最后一个(返回的)字符串是分隔符字符串连接的字符串。

Syntax:

句法:

String.join(iterable)

Example 1: Joining string with hyphen ('-') character

示例1:使用连字符('-')连接字符串

# s as separator string s = "-"# str as sequence of stringsstr = ("Hello", "World", "How are?")# join and print the stringprint (s.join(str))

Output

输出量

Hello-World-How are?

Example 2: Joining string with spaces, a student detail is provided as string sequences

示例2:将字符串与空格连接,将学生详细信息作为字符串序列提供

# s as separator string (contains - space)s = " "# a student detailsfirst_name = "Amit"second_name = "Shukla"age = "21"branch = "B.Tech"# creating string sequencesstr = (first_name, second_name, age, branch)# value of str before joiningprint "str before join..."print (str)# join and print the stringprint "str after join..."print (s.join(str))

Output

输出量

str before join...    ('Amit', 'Shukla', '21', 'B.Tech')    str after join...    Amit Shukla 21 B.Tech

翻译自:

转载地址:http://uexzd.baihongyu.com/

你可能感兴趣的文章
WPF设计の画刷(Brush)
查看>>
HTML学习笔记
查看>>
selinux详解及配置文件
查看>>
性能优化之数据库优化
查看>>
Swift - 继承UIView实现自定义可视化组件(附记分牌样例)
查看>>
android自定义viewgroup实现等分格子布局
查看>>
springboot 配置mybatis
查看>>
10慕课网《进击Node.js基础(一)》初识promise
查看>>
JavaScript事件
查看>>
mysql 命令之工作小结
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
UVa 1658,Admiral (拆点+限制最小费用流)
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
Careercup - Facebook面试题 - 5890898499993600
查看>>