PYTHON CREATING CLASS AND ATTRIBUTE :
1. Create a Class and initialize attribute of the following:
Class name: Student
Attribute: First Name
Last Name
Sex
Age
2. From the created class, create 5 objects, and display it using pretty table.
class Student:
def __init__(self, Firstname,LastName,Sex,age):
self.Firstname = Firstname
self.LastName = LastName
self.Sex = Sex
self.age = age
def display(self):
print("First Name: ",self.Firstname)
print("Last Name: ",self.LastName)
print("Sex: ",self.Sex)
print("Age: ",self.age)
s1=Student("John","Smith","Male",25);
s1.display();
s1=Student("Mary","Jack","Female",23);
s1.display();
s1=Student("Ann","Johns","Female",20);
s1.display();
s1=Student("Jafeth","Brandon","Male",32);
s1.display();
s1=Student("David","Stanly","Male",19);
s1.display();
Comments
Leave a comment