Python笔记:1.3.2元组操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bq_cui/article/details/89920553
# -*- coding: utf-8 -*-
"""
Created on Tue May  7 14:22:28 2019

@author: Administrator
"""

t=tuple('This is Python!')
print(t)

t1=t+([1,2],)
print(t1)

#可以对元组中的可变元素进行更改
t1[-1].append(3)
print(t1)

country=('中国', '美国', '日本', '俄罗斯', '法国')
a1,a2,a3,a4,a5=country
print(a1,a2,a5,a3,a4)

运行:

('T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'P', 'y', 't', 'h', 'o', 'n', '!')
('T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'P', 'y', 't', 'h', 'o', 'n', '!', [1, 2])
('T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'P', 'y', 't', 'h', 'o', 'n', '!', [1, 2, 3])
中国 美国 法国 日本 俄罗斯

猜你喜欢

转载自blog.csdn.net/bq_cui/article/details/89920553