#创建元组
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)

 

相关文章:

  • 2021-12-03
  • 2022-01-18
  • 2019-07-07
  • 2021-12-22
  • 2021-05-05
  • 2021-08-31
  • 2021-12-03
  • 2021-10-19
猜你喜欢
  • 2019-09-14
  • 2019-10-06
  • 2021-07-07
  • 2021-10-31
  • 2021-12-03
  • 2021-12-03
  • 2021-12-03
  • 2021-12-03
相关资源
相似解决方案