Python Constructor

Опубликовано: 11 Октябрь 2021
на канале: Nuruzzaman Faruqui
3,109
45

The constructor is a common term for object-oriented programming. It is a particular type of subroutine and is called when an object is created. In this lesson, you will learn how to create a constructor in Python.

In the first part of the lesson, we learn how to create a constructor. Then we will practice with one more example. I hope this lesson will help you to understand how to create a constructor in Python.

The Python code used in this lesson:

class Keyboard:
def __init__(self, language, connection):
self.language = language
self.connection = connection

def definition(self):
print("Keyboard is an input device")

def numer_of_keys(self):
print("There are 101 keys")


my_keyboard = Keyboard('English', 'wireless')
print(my_keyboard.connection)


class AboutMe:
def __init__(self, name, address, occupation):
self.name = name
self.address = address
self.occupation = occupation

def talk(self):
print(f"My name is {self.name}. I am from {self.address}. And "
f"I am a {self.occupation}")


faruqui = AboutMe('Nuruzzaman Faruqui', 'Bangladesh', 'teacher')
faruqui.talk()

‘You are free to copy, edit, use and distribute this code without crediting the author. Enjoy copyright-free content.’ – Nuruzzaman Faruqui.


На этой странице сайта вы можете посмотреть видео онлайн Python Constructor длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Nuruzzaman Faruqui 11 Октябрь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 3,109 раз и оно понравилось 45 зрителям. Приятного просмотра!