RUVIDEO
Поделитесь видео 🙏

4.1 Python Classes

📁 Обучение 👁️ 16 📅 02.12.2023

Defining Class
• Class definitions contain statements and function definitions. Class is like a blueprint/prototype and Objects are instances created from class. • When a class definition is entered, a new namespace is created, and used as the local scope — thus, all assignments to local variables go into this new namespace. Function definitions bind the name of the new function here.
Class and def statements
• class statement defines a block of code and attaches its local namespace to a class, for use in object oriented programming (OOP). • def statement defines a function or method.
Class Objects Object is an instance of a class which support two kinds of operations: – Class instantiation: x = class1.c1() – Attribute references: x.i, x.__doc__ – Method references: x.f1()
Calling class obj (instantiation operation)
Calling a class object may create an empty object or class object instantiated with initial state. When a class defines __init__() method, class instantiation automatically invokes __init__() for the newly-created class instance. def __init__(self): self.data = []
__init__ method
__init__() method may have arguments which are passed to the class instantiated.
Class and Instance Variables Class variables for attributes and methods are shared by all instances of the class. Instance variables are unique to each instance. If class variables involve mutable objects such as lists and dictionaries, they can used to update by all instances. If same is defined in function, it will be instance variable and not shared by all.
Method – self argument
• The first argument of a method is called self. And this is just a convention and has no special meaning.
Python’s class features • Provide all the standard features of Object Oriented Programming (OOP). • Inheritance, multiple inheritance supported. • Allows polymorphism, not only within a class hierarchy but also by duck typing. Derived class can override any methods of its base class or classes. • A method can call the method of a base class with the same name. Like modules, classes are created at runtime, and can be modified further after creation.
Python’s class features
• Any object can be used for any type, and it will work so long as it has the proper methods and attributes. • Everything in Python is an object, including classes, functions, numbers and modules. • Python supports metaclasses, an advanced tool for enhancing classes' functionality. • Limited support for private variables using name mangling.
Function defined outside the class
• Any function object that is a class attribute defines a method for instances of that class. It is not necessary that the function definition is enclosed in the class definition.
Class defining some properties
Class and static methods
• Python allows the creation of class methods and static method via the use of the – @classmethod and @staticmethod decorators. • The first argument to a class method is the class object instead of the self-reference to the instance. • A static method has no special first argument. Neither the instance, nor the class object is passed to a static method.
Names / alias and Objects
• Objects with multiple names/ alias point to same object like pointers.
OOPs - Notes • When we first describe a class, we are defining it (with functions). • Encapsulation: ability to group similar functions and variables together. • The word 'class' can be used for a class well as for the instance. • Inside a class - a variable is known as an 'attribute‘ and a function is known as a 'method‘. • A class is known as a 'data structure' - it holds data, and the methods to process that data.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «4.1 Python Classes», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.