Tuesday Tip #50: What is a "method" in Python? 🐍


Hi Reader,

Next week, I’ll be offering a Black Friday sale on ALL of my courses.

I’ll send you the details this Thursday! 🚨


πŸ‘‰ Tip #50: What is a "method" in Python?

In Python, a method is a function that can be used on an object because of the object's type.

For example, if you create a Python list, the "append" method can be used on that list. All lists have an "append" method simply because they are lists:

If you create a Python string, the "upper" method can be used on that string simply because it's a string:

To be clear, my_list doesn't have an "upper" method and my_string doesn't have an "append" method. That's because methods only exist for a particular object if they have been explicitly defined for that type of object.


☎️ Calling a method

To call a method, the format is object_name.method_name(), and any arguments to the method are listed within the parentheses.

The method implicitly acts on the object being named, and thus some methods don't have any stated arguments since the object itself is the only necessary argument. For example, my_string.upper() doesn't have any listed arguments because the only required argument is the object itself, my_string.


πŸ““ What about modules?

One common point of confusion relates to the following:

Is "sqrt" a method of the "math" object? No. Instead, this is how you call the "sqrt" function from the "math" module.

The format being used here is module_name.function_name() instead of object_name.method_name().

You can distinguish between the two formats by examining the imports to see whether or not the part before the period ("math", "my_list", "my_string") was imported as a module.


🐍 Want to level up your Python skills?

Whether you're new to Python or just want to fill in the gaps in your knowledge, I'd invite you to join 500+ happy students in my signature Python course, Python Essentials for Data Scientists.


πŸ‘‹ See you on Thursday!

In two days, I'll be sending you the details of my Black Friday sale! πŸ˜„

- Kevin

P.S. Playing a prank on Google Street View​

​

Did someone AWESOME forward you this email? Sign up here to receive more Data Science tips!

Learn Artificial Intelligence from Data School πŸ€–

Join 25,000+ intelligent readers and receive AI tips every Tuesday!

Read more from Learn Artificial Intelligence from Data School πŸ€–

Hi Reader, On Friday, I announced my forthcoming book, Master Machine Learning with scikit-learn. In response, my Dad asked me: How does the subject of this book relate to Artificial Intelligence? In other words: What's the difference between AI and Machine Learning? Ponder that question for a minute, then keep reading to find out how I answered my Dad... πŸ‘‡ AI vs Machine Learning Here's what I told my Dad: You can think of AI as a field dedicated to creating intelligent systems, and Machine...

Hi Reader, Yesterday, I posted this announcement on LinkedIn and Bluesky and X: Kevin Markham @justmarkham Dream unlocked: I'm publishing my first book! πŸŽ‰πŸŽ‰πŸŽ‰ It's called "Master Machine Learning with scikit-learn: A Practical Guide to Building Better Models with Python" Download the first 3 chapters right now: πŸ‘‰ https://dataschool.kit.com/mlbook πŸ‘ˆ Thanks for your support πŸ™ 1:47 PM β€’ Sep 11, 2025 1 Retweets 5 Likes Read 1 replies This has been a dream of mine for many years, and I'm so excited...

Hi Reader, Hope you’ve had a nice summer! β˜€οΈ As for me, I’ve been finishing my first ever book! I can’t wait to tell you about it and invite you to be part of the launch… stay tuned πŸ‘€ Today's email focuses on a single important topic: AI’s impact on your mental health 🧠 Read more below! πŸ‘‡ Sponsored by: Morning Brew The 5-Minute Newsletter That Makes Business Make Sense Business news doesn't have to be dry. Morning Brew gives you the biggest stories in business, tech, and finance with quick...