Python05-09_字符串的分割与合并
2021-03-29 00:27
标签:range app += 分隔符 print pytho load append div 循环100w次和循环1000w次 Python05-09_字符串的分割与合并 标签:range app += 分隔符 print pytho load append div 原文地址:https://www.cnblogs.com/xujie-0528/p/13620228.htmlspilt()分割和join()合并
1 a = "to be or not to be"
2 a = a.spilt()
3 print(a)
4 [‘to‘,‘be‘,‘or‘,‘not‘,‘to‘,‘be‘]
1 a = [‘wo‘,‘ai‘,‘ni‘]
2 a = ‘*‘.join(a)
3 print(a)
4 ‘wo*ai*ni‘
pratice: 比较加法和join两种拼接方式的效率
1 a = ""
2 import time
3 time01 = time.time()
4 for i in range(10000000):
5 a+= "sxt"
6 time02 = time.time()
7 print("时间:"+str(time02 - time01))
8
9 time03 = time.time()
10 li = []
11 for i in range(10000000):
12 li.append("sxt")
13
14 a="".join(li)
15
16 time04 = time.time()
17 print("时间:"+str(time04 - time03))
上一篇:【leetcode】重新排列数组
下一篇:Java 之 数组概述
文章标题:Python05-09_字符串的分割与合并
文章链接:http://soscw.com/index.php/essay/69285.html