This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - If Else statements | |
x = -100 | |
if x != 100 and x > 0: | |
print("x is = ") | |
print(x) | |
if x > 0: | |
print("x is positive") | |
else: | |
print("x is negative") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners-if..elif..else statements + nested IF statements | |
#------------nested IF statements-------- | |
x = 10 | |
if x >= 0: | |
print("x is positive ") | |
if (x%2) == 0: | |
print("x is even") | |
else: | |
print("x is odd") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners 10 - Boolean, Comparison Operators and Logical Operators in Python | |
https://www.youtube.com/watch?v=0MBLkNlffT0 | |
>>> True | |
True | |
>>> False | |
False | |
>>> true | |
Traceback (most recent call last): | |
File "<input>", line 1, in <module> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> x = [3, 5, 4, 9, 7, 10] | |
>>> x | |
[3, 5, 4, 9, 7, 10] | |
>>> x[0] | |
3 | |
>>> x[4] | |
7 | |
>>> y = ['max', 1, 15.5, [3, 2]] | |
>>> y[0] | |
'max' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> x = (1,5,3,4,8) | |
>>> | |
>>> x | |
(1, 5, 3, 4, 8) | |
>>> x[0] | |
1 | |
>>> x[4] | |
8 | |
>>> x[100] | |
Traceback (most recent call last): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> A = {1, 2, 5, 4, 7, 9, 2} | |
>>> A | |
{1, 2, 4, 5, 7, 9} | |
>>> len(A) | |
6 | |
>>> A.add(10) | |
>>> A | |
{1, 2, 4, 5, 7, 9, 10} | |
>>> A.add(10) | |
>>> A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> D = {'name': 'max', 'age': 14, 'year': 2004} | |
>>> D | |
{'name': 'max', 'year': 2004, 'age': 14} | |
>>> D['name'] | |
'max' | |
>>> D['age'] | |
14 | |
>>> E = {'name':'Tom', 15: 15, 15.1:15.1, True: True, (2,3): 5} | |
>>> E[(2,3)] | |
5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - while Loop | |
#--------- Example 1 --------------- | |
i = 0 | |
while True: | |
print("the value of i is : ", i) | |
i += 1 # i = i + 1 | |
else: | |
print("Finished while loop") | |
#--------- Example 2 --------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - For Loop | |
print("For loop with Lists") | |
A = [0, 1, 2, 3, 4, 5] # list | |
for x in A: | |
print(x) | |
print("For loop with Tuples") | |
B = (0, 1, 2, 3, 4, 5) # tuple | |
for x in B: | |
print(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - break and continue | |
a = [0, 1, 2, 3, 4, 5] | |
print('-----------break for loop---------------------') | |
for x in a: | |
if x == 2: | |
break | |
print(x) | |
print('-----------continue for loop---------------------') | |
for x in a: |
OlderNewer