Python: Magic Methods

Lab Steps

lock
Web IDE Review
lock
Magic Methods
lock
Truthiness
lock
Demonstrate Your Knowledge

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyIntermediate
Time Limit2h
Students19
Ratings
3/5
starstarstarstar-borderstar-border

Description

Learn to control the way that objects interact with the Python language syntax and built-in functions.

Magic methods allow user-defined objects to behave more like built-in objects. They allow objects to interact with the runtime and language syntax in a more Pythonic manner. This lab covers commonly used magic methods through hands-on learning.

Learning Objectives:

  • Cover common magic methods:
    • __init__
    • __str__
    • __int__
    • __float__
    • __repr__
    • __eq__
    • __lt__
    • __gt__
    • __le__
    • __ge__
    • __bool__
    • __len__

Prerequisites:

  • Familiar with:

    • Classes
    • Methods
    • Callables
  • Proficient with:

    • The Python runtime
    • The Python language syntax
About the Author
Students95980
Labs28
Courses46
Learning paths54

Ben Lambert is a software engineer and was previously the lead author for DevOps and Microsoft Azure training content at Cloud Academy. His courses and learning paths covered Cloud Ecosystem technologies such as DC/OS, configuration management tools, and containers. As a software engineer, Ben’s experience includes building highly available web and mobile apps. When he’s not building software, he’s hiking, camping, or creating video games.

Covered Topics