Skip to content

Commit a4b968b

Browse files
Python basic series tutorial code files.
0 parents  commit a4b968b

28 files changed

+1219
-0
lines changed

Diff for: and_or_not_examples.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri Jul 30 00:43:05 2021
4+
5+
@author: mjach
6+
"""
7+
8+
'''AND, OR, NOT examples'''
9+
10+
# and examples
11+
#if both are true then and expression will be true
12+
13+
answer_one = True
14+
answer_two = True
15+
#print('True or False :', answer_one and answer_two)
16+
17+
#if one the variable is false answer will be false
18+
answer_one = False
19+
answer_two = True
20+
#print('\nTrue or False :', answer_one and answer_two)
21+
22+
#or operator example
23+
#if one of the varaible is True answer will be true
24+
answer_one = True
25+
answer_two = True
26+
#print('\nTrue or False :', answer_one or answer_two)
27+
28+
answer_one = False
29+
answer_two = True
30+
#print('\nTrue or False :', answer_one or answer_two)
31+
32+
#if both false the result will be false
33+
answer_one = False
34+
answer_two = False
35+
#print('\nTrue or False :', answer_one or answer_two)
36+
37+
#not operator examples
38+
# not represent reverse in boolen
39+
# if its true will return false, and if it is false will return false
40+
answer_one = True
41+
print('\nTrue or False :', not answer_one)
42+
43+
answer_one = False
44+
print('\nTrue or False :', not answer_one)

Diff for: break_examples.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Jul 31 20:19:51 2021
4+
5+
@author: mjach
6+
"""
7+
8+
'''how to use break examples'''
9+
10+
fruit_list = ['apple', 'banana', 'orange', 'watermelon']
11+
12+
# for fruit in fruit_list:
13+
# print(f'The fruit name is :{fruit}')
14+
# if fruit == 'orange':
15+
# break
16+
17+
'''How to do break in while loop'''
18+
# fruit = 'orange'
19+
# while True:
20+
# if fruit in fruit_list:
21+
# print(f'The fruit is found: {fruit}')
22+
# break
23+
24+
'''How to do break in while loop'''
25+
counter = 0
26+
while True:
27+
counter = counter + 1
28+
if counter == 20:
29+
print(f'Count has been done to : {counter}')
30+
break

Diff for: comparisons_examples.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Thu Jul 29 03:31:58 2021
4+
5+
@author: mjach
6+
"""
7+
8+
'''Comparisions example with numbers '''
9+
10+
# > greater than sign
11+
# >= greater than equal to sign
12+
# < less than sign
13+
# <= less than equal to sign
14+
15+
# print('100 < 200 =', 100 < 200)
16+
# print('100 <= 100 =', 100 <= 100)
17+
# print('100 < 50 =', 100 < 50)
18+
# print('100 <= 90 =', 100 <= 90)
19+
20+
# print('\n') # to get a new line
21+
22+
# print('200 > 100 =', 200 > 100)
23+
# print('200 >= 200 =', 200 >= 200)
24+
# print('200 > 500 =', 200 > 500)
25+
# print('200 >= 500 =', 200 >= 500)
26+
27+
# print('-20 is greater than 20 ?:', -20 > 20)
28+
29+
'''
30+
Equality
31+
Comparisions example with equals(==) and not equals(!=)
32+
will return boolen result either True or False
33+
'''
34+
35+
answer_one = 1
36+
answer_two = 1
37+
38+
#print('True or False:',answer_one == answer_two)
39+
40+
answer_one = 5
41+
answer_two = 1
42+
#print('True or False:',answer_one != answer_two)
43+
44+
answer_one = 'apple'
45+
answer_two = 'apple'
46+
47+
# print('True or False:',answer_one == answer_two)
48+
# print('True or False:',answer_one != answer_two)
49+
50+
'''Identity check
51+
is or is not key words. (is) is similiar to == and (is not) is similiar to !=
52+
'''
53+
fruit_list_one = ['apple', 'banana']
54+
fruit_list_two = ['apple', 'banana']
55+
56+
#checking for equality
57+
58+
#print(fruit_list_one == fruit_list_two) # will give true or false result
59+
60+
#checking for identity
61+
# both list has different memory address so when checking for identy
62+
# it will give false result because both list has different memory address.
63+
64+
#print(fruit_list_one is fruit_list_two) # will give true or false result
65+
66+
'''
67+
is and is not checking for built in types like None, True and False
68+
'''
69+
70+
one = True
71+
72+
print('One is True :',one is True)
73+
74+
two = False
75+
print('Two is fasle:',two is False)
76+
print('Two is not true:', two is not False )

Diff for: continue_examples.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Jul 31 20:31:51 2021
4+
5+
@author: mjach
6+
"""
7+
8+
'''Continue examples'''
9+
10+
fruit_list = ['apple', 'banana', 'orange', 'watermelon']
11+
12+
# for fruit in fruit_list:
13+
# if fruit == 'orange':
14+
# continue
15+
# print(f'The fruit name is :{fruit}')
16+
17+
18+
'''continue and break togather examples'''
19+
# for fruit in fruit_list:
20+
# if len(fruit) !=6:
21+
# continue
22+
# print(f'The fruit name is : {fruit}')
23+
24+
# # if fruit == 'orange':
25+
# # break
26+
27+
'''How to use return statement inside the loop'''
28+
29+
def find_fruit(fruit_name):
30+
for fruit in fruit_list:
31+
print(fruit)
32+
if fruit == 'orange':
33+
return f'we found out the fruit :{fruit}'
34+
35+
#calling the function
36+
print(find_fruit(fruit_list))
37+

Diff for: dict_examples.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Thu Jul 29 00:52:42 2021
4+
5+
@author: mjach
6+
"""
7+
8+
'''how to create dict.'''
9+
my_dict = {} # empty dict
10+
another_way_dict = dict() # empty dict
11+
12+
# print('What type is it?', type(my_dict))
13+
# print('\nWhat type is it?', type(another_way_dict))
14+
15+
'''how to create dict with items'''
16+
17+
my_dict_with_items = {1: 'apple', 2: 'banana', 3: 'orange'}
18+
19+
'''how to find out length of the dict'''
20+
21+
#print('\nlength of the dict:', len(my_dict_with_items))
22+
23+
'''how to find out key is exits or not'''
24+
25+
# print('\nTo find out key exits or not:', 5 in my_dict_with_items)
26+
# print('\nTo find out key exits or not:', 1 in my_dict_with_items)
27+
28+
'''how to find out value by the key'''
29+
30+
# print('\nTo find out the value:', my_dict_with_items[2])
31+
# #print('\nTo find out the value:', my_dict_with_items[4]) # will throw key error
32+
# print('\nTo find out the value:', my_dict_with_items.get(4)) # will not throw error but rather it will give none
33+
34+
'''how to get all the keys and values'''
35+
print('\nTo get all the keys and values from dict.:', my_dict_with_items.items())
36+
37+
'''how to get only keys from the dict'''
38+
39+
print('\nTo get all the keys only from dict.:', my_dict_with_items.keys())
40+
41+
'''how to get only values from the dict'''
42+
43+
print('\nTo get all the keys only from dict.:', my_dict_with_items.values())
44+
45+
'''how to add new items in the dict'''
46+
47+
my_dict_with_items[6] = 'watermelon' # key value pairs
48+
print('\nTo add new items in the dict',my_dict_with_items.items())
49+
50+
'''how to add or update two dict togather'''
51+
52+
new_dict = {7: 'cucumber', 8: 'carrot'}
53+
54+
my_dict_with_items.update(new_dict)
55+
print('\nUpdated dict now :', my_dict_with_items)

Diff for: first_program.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Thu Jul 15 01:36:38 2021
4+
5+
@author: mjach
6+
"""
7+
8+
print('Hi there')#this is a comment
9+
10+
11+
# =============================================================================
12+
# print('Hi there')
13+
# print('Hi there')
14+
# print('Hi there')
15+
# print('Hi there')
16+
# =============================================================================
17+
18+
'''
19+
print('Hi there')
20+
print('Hi there')
21+
print('Hi there')
22+
print('Hi there')
23+
'''

Diff for: for_loop_examples.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Fri Jul 30 01:40:11 2021
4+
5+
@author: mjach
6+
"""
7+
8+
'''For look examples'''
9+
10+
my_fruits_list = ['apple', 'orange', 'banana', 'watermelon']
11+
12+
#checking is the fruit in my list
13+
print('Is this fruit in my list?:', 'apple' in my_fruits_list)
14+
15+
'''for loop example'''
16+
# for fruit in my_fruits_list:
17+
# print(f'Fruit name is :{fruit}')
18+
19+
'''how to use range() function in for loop -
20+
here range 0 is inclusive I mean 0 will print it will start from 0
21+
and 4 is exclusive I mean 4 will not print, it will stop to number 3
22+
'''
23+
24+
# for number in range(11):
25+
# print(f'Number is : {number}')
26+
27+
'''How to print specific number within range
28+
we can specify start and end.
29+
here number 1 is inclusiveand
30+
number 10 is exclusive
31+
'''
32+
# for number in range(1, 10):
33+
# print(f'Here number will print from 1 to 9: {number}')
34+
35+
'''range() function another use
36+
specify start, end, increment
37+
'''
38+
39+
# for number in range(2, 20, 2):
40+
# print(f'Number is :{number}')
41+
42+
'''How to print out the index of the items
43+
we can use buit in function enumerate
44+
'''
45+
46+
# for index, fruit in enumerate(my_fruits_list):
47+
# print(f'Fruit :{fruit} is at index no : {index}')
48+
49+
'''how to use for loop in dictionary'''
50+
51+
my_fruit_dict= {1:'apple', 2:'orange', 3:'banana', 4:'watermelon'}
52+
53+
# for fruit in my_fruit_dict:
54+
# print(f'That will return only keys of the dict.: {fruit}')
55+
56+
for keys, values in my_fruit_dict.items():
57+
print(f'Fruit :{values} is at {keys} ')

Diff for: functions_python.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon Jul 19 01:38:51 2021
4+
5+
@author: mjach
6+
"""
7+
#simple function example
8+
def my_function():
9+
print('Hi it is a function.')
10+
11+
#function example with arguments
12+
def function_with_arguments(greeting, name):
13+
print('Hi, %s, I wish you all the best %s'%(greeting, name))
14+
15+
# return function example
16+
def adding_two_numbers(a, b):
17+
return a + b
18+
19+
# calling the functions
20+
21+
my_function() # calling first function
22+
23+
function_with_arguments('Good morning', 'Mohammed')# calling function with the arguments
24+
25+
result_two_numbers = adding_two_numbers(5, 4)# calling function that return
26+
27+
print(result_two_numbers) # print the result of the function

0 commit comments

Comments
 (0)