Python中字符串、列表、元组序列共用的三种方法:+、*、in
作者:互联网
合并: +
(1)字符串的合并:strA = "hello" strB = "world"
print(strA+strB)
(2)列表的合并: listA = list(range(10)) listB = list(range(11,21)) print(listA+listB)
复制:*
(1)print(strA*3) # 输出3次hello
(2)print(listA) # 输出3次0——9
判断是否存在:in
(1)print("h" in strA) #判断h在字符串A中是否存在,返回值为布尔类型。` # true
(2)print("PP" in listA) #false
(3)dictA = {"name":"lucy"} print("name" in dictA) # true
标签:Python,list,元组,字符串,strB,print,共用,strA,listA 来源: https://www.cnblogs.com/yingsilu/p/15332599.html