Friday, July 10, 2020

Class Object Constructor Alternative Constructor

#this lecture is 53,54,55,56,57,58# Class is a template where we fill 
the things according to requirements
class student:
    pass   # if we donot want to enter any method or function  
          # then we use pass other wise error will occure
.harry = student() #class object or instancetarry = student()
harry.name = "Harry" #set properties to object.
harry.standard = 12
harry.section = "A"
tarry.name = "Tarry"
tarry.section = "B"
print(f"My name is {harry.name}, the section of tarry is {tarry.section}")
tarry.subjects = ["urdu","math","Chemistry","Biology"]
print(tarry.subjects)
#55 instance or object and class veriables

class Employee:
    no_of_leaves = 8    
pass
ali = Employee()
sameer = Employee()
ali.name = "Ali"
ali.salary = 50000
ali.role = "Data Scientist"
sameer.name = "Sameer"
sameer.salary = 60000
sameer.role = "Android Developer"
print(Employee.no_of_leaves)
print(Employee.__dict__) # show attributes associated with employee class
Employee.no_of_leaves = 9
print(Employee.no_of_leaves)

#56 Use of Self in Class

class Employee2:
    total_leaves = 8    
def printDetails(self):
        return f"name is {self.name}, Salary {self.salary}, role {self.role}"
Akram = Employee2();
Akram.name = "Akram"
Akram.salary = 54222
Akram.role = "MyRol"
print(Akram.printDetails())# here Akaram is self.

#57 Class Constructur __init__

class Employee3:
    def __init__(self,ename,esalary,erole):  #Creating Constructor     
   self.name = ename      # assign the value to arugments       
 self.salary = esalary
        self.role = erole
Shaiz = Employee3("Shaiz",2542,"Instuctor") # pass the value in Consturctor
print(f"Name: {Shaiz.name}, Salary: {Shaiz.salary}, Role: {Shaiz.role}") #print the values

#57 Class Mehtod

class Employee4:
    leavs = 45    
@classmethod   
 def change_leaves(cls, newleaves): # if we want to class level change then we can use the class                                    
# class method to change it permanenetly.        
cls.leavs = newleaves
        return newleaves
asad = Employee4()
print(f"before changing the leaves: {asad.leavs}")
l = asad.change_leaves(34)
print("Asad New Leaves",l)
print("Asad old leaves: ",asad.leavs)
Amjad = Employee4()
print(Amjad.leavs)

# 58 Class method as alternative Constructor

class Employee5:
    def __init__(self,ename,esalary,erole):  #Creating Constructor           
self.name = ename      # assign the value to arugments           
self.salary = esalary
           self.role = erole
    @classmethod   
 def from_dash(cls,string):
        return cls(*string.split("-"))
Basit = Employee5.from_dash("Basit Ali-4511-student")
print(f"Name {Basit.name} Salary: {Basit.salary}, Role: {Basit.role}")

Lec # 52 Python Decorators

# #DECORATORS ARE THE MODIFYING THE FUNCTIONS# 
def function1():
#     x = print("This is simple function 1")
#     return "this is old"## function2 = function1 
# Coppying function# del function1
 # function 1 is coppied in function 2 so, its fine# print(function2())

def dec1 (func1):
    def nowexe():
        print("Now Execute function is runs!")
        func1() #it is location where the function 
                #having decoration will execute like WhoIsShaiz       
        print("Executed")
        return nowexe
@dec1def whoIsShaiz():
    print("Shaiz is a good boy")
whoIsShaiz()

Thursday, July 9, 2020

Python Variable and IF Statement input statement

var1 = "hello world"
print(var1)
var2 = 4
var3 = 36.7
print(var2,type(var3))
var = 454
sum = var * 2.22
print (sum)
print (set([1,2,3]))
var6 = "pakistan my CountrY"
print(var6.upper())
print(var6.lower())
print(int(var3))
print("pakistan " + str(var2))
print("black holes")
a = 45; b= 65; c = 59sum = a +b +c
print(sum)
a = 10b = 50if(a>b):
    print("A is greater")
elif(b==a):
    print("A and B are equal")
else:
    print("B is greater")

'''print (10 * "Hello World\n\n")

print("Enter your name")

name = int(input())

value =str(( name +22))

print(" your result is " + value)'''

print("Enter first number:")
number1 = int(input())
print("Enter second number:")
number2 = int(input())
sum = number1 + number2
print("sum of ",number1,"and",number2," is ",sum)