美文网首页
Python学习心得小记

Python学习心得小记

作者: 暖love阳阳 | 来源:发表于2023-01-15 11:41 被阅读0次

String格式化方式总结

a = b = 1

str = f"{a}+{b} = {a+b}"

str = "%d+%d = %d" % (a , b, a+b)

str = "{} + {} = {} ".format(a , b, a+b, end="\t")

str *= 4 #连续复制4个字符串

str = str[::-1] #字符串倒序展示

Array 操作方法总结

list1 = [1,2,4,5,'Word']

list1.append(6)

list1.pop(-1)

list1.remove(5)

list1.reverse()

list1.insert(0,'Hello')

list2 = list1.copy()

list2 += list1

Tuple 操作类似Array,但是元素值不可修改

tup1 = (1,2,3,4,5,'Word')

tup2 += tup1

tup3 = tuple(list1) #列表转元组

listTuple = [tup1,tup2,tup3)]

list3 = list(tup2) #元组转列表

list4 = [item for t in listTuple for item in t]  #元组元素列表转列表

list5 = list(itertools.chain(*listTuple)) #元组元素列表转列表

相关文章

网友评论

      本文标题:Python学习心得小记

      本文链接:https://www.haomeiwen.com/subject/qbcacdtx.html