Example # 01:
Python object and classes / Object oriented programming / Python oops:
In this article you will learn object oriented programming with example, the object oriented programming is consist of classes and object. To use these classes we developed a good script in any other object programming languages.
What is Class?
In object oriented programming a class is consist of method which include of object and data. After declare a class you need to write the instance of class in oops a class may have many instant and it depend on your main class. So I clear this with following simple example.
Suppose you want to make a studio information module , you need to first write a class name student then you write its instant like first name of student. So in this first name is an instant or object of student class.
Syntax :
class student:
pass
#object or instant
Sadaqat = student()
Sulman = student()
Basharat= student
class student:
pass
#object or instant
Sadaqat = student()
Sulman = student()
Basharat= student
#data of object
Sadaqat.course= 'MCS'
Sulman.course= 'BSC'
Basharat.course= 'MBA'
print('Course :',Sadaqat.course, Sulman.course, Basharat.course)
Python Class And Object || Example # 02
To understanding the class and object is very difficult in any programming language I clear it with following simple and easy example.
class users :
pass
#object
admin= users()
user = users()
#assign values
admin.password='admin123'
user.password ='user123'
pwd = input('Enter Password :')
if pwd == admin.password or pwd == user.password:
print ('Success Login')
else:
print('Faild Login')
Pingback: Python Inheritance And Composition | How To Use | GSS TECHNOLOGY
Pingback: Free PHP MySQL POS With Source Code 2021 | GSS TECHNOLOGY