Classes and Methods Cheat Sheet
In the past few videos, we’ve seen how to define classes and methods in Python. Here, you’ll find a run-down of everything we’ve covered, so you can refer to it whenever you need a refresher.
Defining classes and methods
Classes and Instances
- Classes define the behavior of all instances of a specific class.
- Each variable of a specific class is an instance or object.
- Objects can have attributes, which store information about the object.
- You can make objects do work by calling their methods.
- The first parameter of the methods (self) represents the current instance.
- Methods are just like functions, but they can only be used through a class.
Special methods
- Special methods start and end with __.
- Special methods have specific names, like __init__ for the constructor or __str__ for the conversion to string.
Documenting classes, methods and functions
- You can add documentation to classes, methods, and functions by using docstrings right after the definition. Like this:
출처 : google crash course on python 강의
'프로그래밍 언어 > [Python]스터디' 카테고리의 다른 글
[module] psutil 사용하기 (python system and process utilitis) (0) | 2020.02.09 |
---|---|
[module] shutil 모듈 사용하기 (High-level file operations) (0) | 2020.02.09 |
[읽을 거리]Dictionary Methods Cheat Sheet (0) | 2020.01.30 |
[읽을 거리]Lists and Tuples Operations Cheat Sheet (0) | 2020.01.30 |
[읽을 거리] Formatting Strings Cheat Sheet (0) | 2020.01.29 |