首页 > IT职业 > IT图书 > python改变元组的变量

1、说明
虽然不能修改元组的元素,但是可以给存储元组的变量赋值。因此,如果要修改元组的元素,需要重新定义元组。
相对于列表,元组是更简单的数据结构,如果需要存储一组值在程序的整个生命周期内,都不变,就可以使用元组。
2、实例
dimensions = (200, 50)
print('原始数据')
for dimension in dimensions:
print(dimension)
print('修改后的数据')
dimensions = (400, 100)
for dimension in dimensions:
print(dimension)
以上就是python改变元组变量的方法,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3153/viewspace-2830225/ ,如需转载,请注明出处,否则将追究法律责任。