ZhangZhihui's Blog |
|
||
2024年7月31日
摘要:
If we want objects of this class to be used in iteration contexts, then they should support the iteration protocol. To make this class iterable, we ca 阅读全文
摘要:
In our first example, we will create iterable objects, which, when iterated over, will give out cubes of numbers, and these objects will support multi 阅读全文
摘要:
There are many built-in functions and methods that return iterables and iterators. Here are a few examples: range() returns an iterable dict.keys() re 阅读全文
摘要:
class Engine: def __init__(self,power): self.power = power def start(self): self.draw_current() self.spin() self.ignite() def draw_current(self): prin 阅读全文
摘要:
We have seen that if we have to define a group of classes that have similar features and show common behavior, we can define a base class and then inh 阅读全文
摘要:
The three main features of object-oriented programming are - encapsulation, inheritance and polymorphism. We have seen the first two, now let us see w 阅读全文
2024年7月30日
摘要:
The order in which Python searches for attributes in base classes is called method resolution order(MRO). It gives a linearized path for an inheritanc 阅读全文
摘要:
The magic methods __str__ and __repr__ are used for converting an instance object into a string. The method __str__ is invoked when an instance object 阅读全文
摘要:
Creating Managed Attributes using properties Properties can be used to create data attributes with special functionality. If you want some extra funct 阅读全文
摘要:
Sometimes we have to write methods that are related to the class but do not need any access to instance or class data for performing their work. These 阅读全文
|
Copyright © 2024 ZhangZhihuiAAA
Powered by .NET 9.0 on Kubernetes |