Python 元组补充

代码

1
2
3
4
5
6
7
8
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# 元组的元素不可被修改,but元组的元素的元素可被修改
t = (11, 22, ['alex', {"k1":"v1"}])
print(t)
t[2].append("xxx")
print(t)

执行

1
2
3
C:\Users\ttlop\AppData\Local\Programs\Python\Python36\python.exe C:/Users/ttlop/PycharmProjects/q1_day2/c10.py
(11, 22, ['alex', {'k1': 'v1'}])
(11, 22, ['alex', {'k1': 'v1'}, 'xxx'])