From 303d63fd043f510bf3fd0490fa7d109785a94917 Mon Sep 17 00:00:00 2001 From: positr0nix Date: Thu, 5 Oct 2017 15:14:50 -0500 Subject: [PATCH] Add tuples example --- sampletuples.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sampletuples.py diff --git a/sampletuples.py b/sampletuples.py new file mode 100644 index 0000000..2ff50b5 --- /dev/null +++ b/sampletuples.py @@ -0,0 +1,30 @@ +# SAMPLE CODE TO ILLUSTRATE TUPLES IN PYTHON + +days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") +print "tuple: ", days + +# a tuple is a collection +for day in days: + print day + +print day[0] + +# we can get each element in a tuple +monday, tuesday, wednesday, thursday, friday, saturday, sunday = days +print monday, tuesday, wednesday, thursday, friday, saturday, sunday + +# A tuple also can have differents types. Arrays, dicts even other tuples +tupleMix = (1,"happy", 3.1416, True, [1,2], {"lang": "English"}, (1,2)) +print tupleMix + +# we can concat tuples +a = (1,2,3) +b = (4,5,6) +c = a + b +print c + +# or multiply a tuple +a = ("hi",) * 4 +print a + +# :) learn more about tuples right here https://docs.python.org/3.1/tutorial/datastructures.html \ No newline at end of file