Advertisement
ZEdKasat

Siddharth- topic: Classes 1

Aug 17th, 2021
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1.  
  2.  
  3. # classes are definition for data format
  4. # you can create your own data type
  5.  
  6. # person -> name, id, age
  7. # students -> name, roll no, age
  8. # computer -> proccessor, ram, gpu, os
  9.  
  10.  
  11. # Bruce - 2 - 18
  12.  
  13.    
  14. class Student:
  15.    
  16.     def __init__(self, n, r, a):   # constructor of the class
  17.         self.name = n
  18.         self.roll_no = r
  19.         self.age = a
  20.    
  21.     def introduction(self):
  22.         print("Hello my name is", self.name,"I am", self.age, "years old and my roll number is", self.roll_no)
  23.  
  24.  
  25.  
  26. # tur = Turtle()
  27.  
  28. b = Student("Bruce", 2, 18) # creating object of the class / creating instance of the class
  29. c = Student("Alfred", 1, 23)
  30.  
  31. # print(b.name)
  32.  
  33. b.introduction()
  34. c.introduction()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement