Skip to content

Commit 0b6ccd7

Browse files
authored
Merge pull request #7 from positr0nix/master
Tuples in python
2 parents 3960872 + 303d63f commit 0b6ccd7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sampletuples.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SAMPLE CODE TO ILLUSTRATE TUPLES IN PYTHON
2+
3+
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
4+
print "tuple: ", days
5+
6+
# a tuple is a collection
7+
for day in days:
8+
print day
9+
10+
print day[0]
11+
12+
# we can get each element in a tuple
13+
monday, tuesday, wednesday, thursday, friday, saturday, sunday = days
14+
print monday, tuesday, wednesday, thursday, friday, saturday, sunday
15+
16+
# A tuple also can have differents types. Arrays, dicts even other tuples
17+
tupleMix = (1,"happy", 3.1416, True, [1,2], {"lang": "English"}, (1,2))
18+
print tupleMix
19+
20+
# we can concat tuples
21+
a = (1,2,3)
22+
b = (4,5,6)
23+
c = a + b
24+
print c
25+
26+
# or multiply a tuple
27+
a = ("hi",) * 4
28+
print a
29+
30+
# :) learn more about tuples right here https://docs.python.org/3.1/tutorial/datastructures.html

0 commit comments

Comments
 (0)