Skip to content

Commit d2b0242

Browse files
committed
add tuple
1 parent 5cde7ea commit d2b0242

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tuple.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/python
2+
#coding:utf-8
3+
4+
# 元组 其内容是不可变的
5+
6+
u = 1,2,3; # 定义
7+
print u;
8+
print len(u);
9+
b = 1, 3, (3, 5); # 可嵌套
10+
print b;
11+
12+
# 元组的封装的逆操作
13+
a = 3;
14+
b = 4;
15+
a, b = (b,a);
16+
print a, b;
17+
18+
def triple(x, y, z):
19+
return (3 * x, 3 * y, 3 * z);
20+
21+
a, b, c = triple(1, 2, 3);
22+
print a, b, c; #3, 6, 9

0 commit comments

Comments
 (0)