Skip to content

Commit a718527

Browse files
Add Python tuple examples
1 parent f65844f commit a718527

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: tuples_sets_booleans.py

+19
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,22 @@
4040

4141
for i in range(5):
4242
print("i is: ", i)
43+
44+
45+
# The tuple() builtin can be used to create tuples in Python.
46+
# In Python, a tuple is an immutable sequence type.
47+
# One of the ways of creating tuple is by using the tuple() construct.
48+
t1 = tuple()
49+
print('t1 =', t1)
50+
51+
# creating a tuple from a list
52+
t2 = tuple([1, 4, 6])
53+
print('t2 from a list =', t2)
54+
55+
# creating a tuple from a string
56+
t1 = tuple('Python')
57+
print('t1 from a string =', t1)
58+
59+
# creating a tuple from a dictionary
60+
t1 = tuple({1: 'one', 2: 'two'})
61+
print('t1 from a dict =', t1)

0 commit comments

Comments
 (0)