Sitemap
Yen Wang

Yen Wang

Curious mind. Interested in both creative and exploitative sides. More about me | https://www.yenwang.dev/

Python — Basic Review before diving deeper 06

Want to recall the memory of Python easily?

5 min readApr 26, 2023

--

Press enter or click to view image in full size

This is the note taken while I learned Python “again”, hope it helps you too.
There are additional links in the article for you to understand further information.

Quick tip |
Find ⚡for each topic

☘️Directory

  • Object Introspection
  • Dunder methods
  • Multiple inheritance
  • M.R.O
  • Functional Programming(F.P.)
  • Difference between OOP & FP

❤️Good Resources

Bro code | Python full course
ZeroToMastery | Pyhton
Codes in Github

⚡Object Introspection

More in GeeksforGeeks

🔹An ability to determine the type of an object at runtime.

🔹Everything in python is an object. Every object in Python may have attributes and methods.

🔹We can dynamically examine python objects — GeeksforGeeks

Built-in functions

Press enter or click to view image in full size

🔸type()

Press enter or click to view image in full size

🔸dir()

Press enter or click to view image in full size
Press enter or click to view image in full size

🔹str()

🔹id()

🔹hasattr()

🔹getattr()

🔹repr()

🔹callable()

🔹issubclass()

🔹isinstance()

🔹sys()

🔹__doc__

🔹__name__

⚡Dunder

🔹Dunder = Double-Underscore

🔹Also called magic method

Get Yen Wang’s stories in your inbox

Join Medium for free to get updates from this writer.

Some Dunder Methods…

  • __init__()
  • __repr__()
  • __str__()
  • __new__()

🔸__str__

Press enter or click to view image in full size
Press enter or click to view image in full size

You can change the default setting by this.

Before changed

Press enter or click to view image in full size

After Changed.

Press enter or click to view image in full size

🔸__len__()

Press enter or click to view image in full size
Press enter or click to view image in full size

Set Default Value

Press enter or click to view image in full size
No matter what it will return 3 anyway.

🔸del

Press enter or click to view image in full size
Press enter or click to view image in full size

print in __del__ method

Press enter or click to view image in full size
Press enter or click to view image in full size

🔸__call__

Press enter or click to view image in full size
Press enter or click to view image in full size

🔸__getitem__

Press enter or click to view image in full size

⚡Multiple Inheritance

Inheritance from multiple classes

Syntax

Press enter or click to view image in full size

Another Example.

Press enter or click to view image in full size
Press enter or click to view image in full size

❌Why is that?

Because we inheritate Wizard first, there is no check_HP function in it.

Press enter or click to view image in full size

Now it works.

If we need to sign in first…

Press enter or click to view image in full size

⚡MRO

MRO(Method Resolution Order)

More in GeeksforGeeks

This order is also called Linearization of a class and set of rules are called MRO(Method Resolution Order). While inheriting from another class. — GeeksforGeeks

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

⚡Functional Programming

Concepts including 4,

🔸Pure Functions

Press enter or click to view image in full size

🔸Recursion

Use function to

GeeksforGeeks | Difference between Recursion & Iteration

Press enter or click to view image in full size
Press enter or click to view image in full size

🔸Functions are First-Class and can be Higher-Order

Some commonly used Higher-Order Functions.

🔹map()

🔹filter()

🔹Lambda Functions

Press enter or click to view image in full size

🔸Variables are Immutable

Press enter or click to view image in full size

⚡Difference

between OOP & Functional Programming

More in GeeksforGeeks

🔸OOP

  • Importance is given to data
  • uses loops for iteration
  • Data used here are mutable

🔸FP

  • Importance is given to functions
  • uses recursion for iteration
  • Data in the functions are immutable

--

--

Yen Wang
Yen Wang

Written by Yen Wang

Curious mind. Interested in both creative and exploitative sides. More about me | https://www.yenwang.dev/