Python基础-元组练习
#创建元组
tuple1=(1,2,3,4,5,6) #元组元素不可直接更改
print(tuple1) #列表关键是中括号[],元组关键是整数和,
temp=() #创建空元组
temp2=(1,) #有逗号隔开即是元组
#元组分片
tuple2=tuple1[:3]
print(tuple2)
a=8*(8) #两数相乘
b=8*(8,) #元组*8,即重复操作符
print("8*(8) is",a,"8*(8,) is",b)
#更新和修改元组
temp=("Li","Yu","Song","Gao") #使用拼接操作符
temp=temp[:2]+("Tang",)+temp[2:] #括号逗号缺一不可!!!
print(temp)
temp1=temp[:2]+temp[3:]
print(temp1)
#运算操作符,比较操作符,逻辑操作符
if temp==temp1:
print(True)
else: #别忘了冒号
print(False)
if temp>temp1 or temp==temp1:
print("temp>=temp1")
else:
print(temp<temp1)