Class in python

# 1st Example
# Normal use of class as usually we do.
# Space in not compulsory.I add space for your easy understanding.
#Pass is use for to pass the programme .But not for pass the programme.Because ex=if you make a function means def so pass not need.But if there is nothing after class means empty then pass need to add.

class Student:
pass
harry=Student()
me=Student()

harry.name="Harry"
harry.Standard="All rounder"
harry.whatisharry="My SIR.If you are in searching any teacher or brother go to:https://www.youtube.com/codewithharry\nBut only in hindi language so sad Lol"

me.name="Alex"
me.Standard="10th in 2020 Ok .who are reading this"
me.whatisme="A student in 2020 .Lol"
print(harry.whatisharry)

#2nd Example. Use of dict in class
class Alex:
pass
alex=Alex()

alex.name="Alexxxxx"
alex.fun="In Programing"
print(alex.__dict__)



# 3rd Example. Use of init in class
class Alex:
def __init__(self,name,fun):
self.name="Alex"
self.fun="IN Programming"
lol=Alex("name","haha")
print(lol.fun)




#4th Example adding a i dont known
# class Employee:
# no_of_leaves = 8
# pass
#
# harry = Employee()
# rohan = Employee()
#
# harry.name = "Harry"
# harry.salary = 455
# harry.role = "Instructor"
#
# rohan.name = "Rohan"
# rohan.salary = 4554
# rohan.role = "Student"
#
# print(Employee.no_of_leaves)
# print(Employee.__dict__)
# Employee.no_of_leaves = 9
# print(Employee.__dict__)
# print(Employee.no_of_leaves)

Comments

Popular posts from this blog

IO BASIC

Y.T Videos downloader [Python]

Convert PDF To Audiobook [Without Python]