Python Programming Course

 1) Lecture 1

# Printing Hello world
print ("Hello world")

# Addition
a = 100
b = 100
c = a + b
print (c)
print (200+500)

# Substraction
a = 100
b = 100
c = a - b
print (c)

# Multiplication
a = 100
b = 100
c = a * b
print (c)

print ("so the sum of {} and {} is {}".format(a,b,c))

2) Python Variables and Constants 

#declaring  and Assigning value to constants
PI = 3.14
GRAVITY = 9.8
print(PI)

#Declaring and assigning value to a variable
a = "Apple"
print(a)

#Changing value of a variable
a = "Aeroplane"
print(a)

a = 100
print (a)

#Assigning Multiple values to a variables
b,c,d = 1, 2.5, "Hello"
print(b,c,d)

#Assigning same value to multiple variables
b = c = d = 5
print(b,c,d)

3) Python Class and Objects 

#Classes and Objects

class MyComplexNumber:
    #Constructor methods
    def __init__(self, real=0, imag=0):
        print("MyComplexNumber constructor executing...")
        self.real_part = real
        self.imaginary_part = imag

    def displayComplex(self):
        print(f"{self.real_part} + {self.imaginary_part}j")

#Create a new object of type MyComplexNumber class
cmplx1 = MyComplexNumber(40,50)

#Calling displayComplex() function
#Output :40 + 50j
cmplx1.displayComplex()

# Create another object of type MyComplexNumber class
# and create a new attribute 'new_attribute'
cmplx2 = MyComplexNumber(60,70)
cmplx2.new_attribute = 80

#Output:(60,70,80)
print((cmplx2.real_part, cmplx2.imaginary_part,cmplx2.new_attribute))

#but cmplx1 object doesn't have attribute 'new_attribute
print(cmplx1)
del cmplx1.real_part
del cmplx1

4)Python Array Implementation

#python Array implimentation

#Defining and declaring  and Arrays
arr = [10,20,30,40,50]
print(arr)

#Accessing elements of array
print(arr[0])
print(arr[1])
print(arr[2])
print(arr[-1]) #Negative Indexing
print(arr[-2]) #Negative Indexing


brands = ["Coke", "Apple", "Google", "Microsoft","Toyota"]
print(brands)

#Finding the length of an array
num_of_brands = len(brands)
print(num_of_brands)

#Adding an element to an array using append()
brands.append("intel")
print(brands)

#Removing elements of an array using indexing
fruits = ["Apple","Banana","Mango","Grapes","Orange"]
fruits[1] = "Pineapple"
fruits[-1] = "Guava"
print(fruits)

#Removing elements from an array
colors = ["violet","indigo","blue","green","yellow","orange"]
print(colors)
del colors[4]
colors.remove("orange")
colors.pop(3)
print(colors)

#Concatenating two Arrays using the + operator
concat = [1,2,3]
print(concat)
concat + [4,5,6]
print(concat)
concat = concat + [4,5,6]
print(concat)

#Repeating/repetaing elements of an array
repeat = ["a"]
print(repeat)
repeat = repeat*5
print(repeat)

#Slicing of an array
sli = [1,2,3,4,5,6,7,8,9,10]
print(sli[2:5])
print(sli[:5])
print(sli[5:])
print(sli[:])

fruits = ["Apple","Banana","Mango","Grapes","Orange"]
print(fruits)
print(fruits[1:4])
print(fruits[ :3])
print(fruits[-4: ])
print(fruits[-3: -1])

#Declaring and defining=g multidimenional array
multd = [[1,2], [3,4],[5,6],[7,8]]
print(multd)
print(multd[0])
print(multd[3])
print(multd[2][1])
print(multd[3][0])

5) Python Keywords and Identifiers

#Python Keywords and Identifiers

#True False
print(5 == 5)
print(5 > 5)

#None
print(None == 0)
print(None == False)
print(None == [])
print(None == None)

def a_void_function():
    a = 1
    b = 2
    c = a + b

x = a_void_function()
print(x)

#and ,or,not
print(True and False)
print(True or False)
print(not False)

#as
import math as myMath
print(myMath.cos(myMath.pi))

#assert
assert 5 > 4
assert 5 == 5


#break
for i in range(11):
    if i == 5:
        break
    print(i)

#Continue
for i in range(1,8):
    if i == 5:
        continue
    print(i)

#Class
class ExampleClass:
    def function1(parameters):
        print("Function0() Executing... ")
    def function2(parameters):
        print("Function2() Executing... ")
ob1 = ExampleClass()
ob1.function1()
ob1.function2()

#def
def function_name(parameters):
    pass
function_name(10)

#del
# a = 10
# print(a)
# del a
# print(a)
# name 'a' is not defined


#if..elif..else
num = 2
if num == 1:
    print("One")
elif num == 2:
    print("Two")
else:
    print("something else..")

#try ..raise...catch...finally
try:
    x = 9
    raise ZeroDivisionError
except ZeroDivisionError:
    print("Division cannot be performed")
finally:
    print("Execution Successfully")

#for
for i in range(1,10):
    print(1)

#from.. import
import math
from math import cos

6) Coming soon......





Post a Comment

0 Comments