Ello and welcome!
Today we are doing some Object-oriented programming in python,
Imagine objects as sot of storages for your variables where they can be used trough functions in class in a better way, more efficient. OOP in python isnt as complex as it looks and i try my best to explain it in my videos. Here is the codes:
1.py
class Book:
def init(self, title, author, pagination=””):
self.title = title
self.author = author
self.pagination = pagination
def printer(self):
print(“Book:”,self.title, ” Author:”, self.author,”;”,self.pagination)
sometitle = “Hello world in python!”
someauthor = “L.L.Cool J.”
somepagination = “33p”
key = Book(sometitle, someauthor, somepagination)
key.printer()
sometitle = “Hello world in Piton”
someauthor = “Samuel L. Motherf.”
key = Book(sometitle, someauthor)
key.printer()
getsomething.py:
class Getclass:
def init(self,word, code=”Python”):
self.word = word
self.code = code
def get(self):
print(“Welcome back :”,self.word)
print(“You are programming in “, self.code)
def getout(self):
print(“Get Out : “, self.word)
and finally
main.py:
import getsomething
keyword = “admin”
key = getsomething.Getclass(keyword)
if keyword == “John”:
key.get()
elif keyword == “admin”:
key.get()
else:
key.getout()
There we go ! Thank you so much for watching/visiting and have a nice day 🙂
