diff --git a/Python/1-for.py b/Python/1-for.py new file mode 100644 index 0000000..ead784d --- /dev/null +++ b/Python/1-for.py @@ -0,0 +1,2 @@ +for i in range(10): + print(i) diff --git a/Python/2-while.py b/Python/2-while.py new file mode 100644 index 0000000..db00e1d --- /dev/null +++ b/Python/2-while.py @@ -0,0 +1,4 @@ +a = 0 +while a < 10: + print(a) + a += 1 diff --git a/Python/3-do-while.py b/Python/3-do-while.py new file mode 100644 index 0000000..bc01018 --- /dev/null +++ b/Python/3-do-while.py @@ -0,0 +1,9 @@ +# There is no do-while loop in python +# But we can emulate it + +a = 0 +while True: + print(a) + a += 1 + if not a < 10: + break diff --git a/Python/4-for-in.py b/Python/4-for-in.py new file mode 100644 index 0000000..5f48f37 --- /dev/null +++ b/Python/4-for-in.py @@ -0,0 +1,14 @@ +dictionary = {'x': 1, 'y': 2, 'z': 3} + +for i in dictionary: + print(i) + +for i in dictionary: + value = dictionary[i] + print(i, value) + +for i in dictionary.values(): + print(i) + +for i in dictionary.items(): + print(i) diff --git a/Python/6-break.py b/Python/6-break.py new file mode 100644 index 0000000..212a9e8 --- /dev/null +++ b/Python/6-break.py @@ -0,0 +1,10 @@ +# There is no break label in python + +flag = True + +while True: + print("Hello") + if flag: + break + +print("There") diff --git a/Python/7-continue.py b/Python/7-continue.py new file mode 100644 index 0000000..6b7266f --- /dev/null +++ b/Python/7-continue.py @@ -0,0 +1,9 @@ +# There is no continue label in python +i = 0 + +while i < 10: + i += 1 + print("Hello") + if i == 5: + continue + print("World") diff --git a/Python/8-forEach.py b/Python/8-forEach.py new file mode 100644 index 0000000..e3e1691 --- /dev/null +++ b/Python/8-forEach.py @@ -0,0 +1,7 @@ +# Python doesn't have functional forEach +# We use a for loop instead + +dictionary = {'x': 1, 'y': 2, 'z': 3} + +for k, v in dictionary.items(): + print(k, v) diff --git a/Python/9-map.py b/Python/9-map.py new file mode 100644 index 0000000..c5be271 --- /dev/null +++ b/Python/9-map.py @@ -0,0 +1,3 @@ +map_obj = map(lambda x: x * 2, [7, 10, 1, 5, 2]) + +print(list(map_obj))