元组-简易版演示

t= tuple()
t
()

t=(1,2,3,‘a’,[1,2])
t
(1, 2, 3, ‘a’, [1, 2])

t[4]
[1, 2]

1 in t
True

#查
2 not in t
False

4 not in t
True

#元组赋值
a=1
b=56
a,b=b,a
a
56

b
1

u=1,2,3,‘a’,[1,2,3]
t
(1, 2, 3, ‘a’, [1, 2])

u
(1, 2, 3, ‘a’, [1, 2, 3])

#,左右两边都是元组
n=1,
type(n)

m=(1)
type(m)

#注意括号不一定为元组
#必须有,
n=(1,)
type(n)

#等号两边元素长度相等
type(t[0])

def printa(*a):
print(a)
printa(1,2,3,‘dsa’,[1,2,3])
SyntaxError: invalid syntax

= RESTART: D:/Python/上课源码/11-10/a.py
(1, 2, 3, ‘dsa’, [1, 2, 3])

= RESTART: D:/Python/上课源码/11-10/a.py
(1, 2, 3, ‘dsa’, [1, 2, 3])

s=‘abc’
l=[1,2,30]
zip(s,l)

#解构
for i in zip(s,l):
print(i)

(‘a’, 1)
(‘b’, 2)
(‘c’, 30)

for m n in zip(s,l):

SyntaxError: invalid syntax

for m,n in zip(s,l):
print(m,n)

a 1
b 2
c 30

你可能感兴趣的:(python学习笔记,python)