Python functions vs methods explained

Python function vs Python method Coming from Java, this confused me at first. In Java, we usually call everything a method. Method in Python: Methods belong to a class or an object. We use the dot (.) operator to call the same like Java e.g. name.upper() emp_list.append("Bob") Function in Python: Functions do not belong to any class or object. We call them directly by name, "without dot" (.) operator. e.g. print("Hello") len("hello") type(10) How do functions like print(), len() and type() such functions work? When Python runs a script, it automatically loads a built-in module called "builtins". This module contains many common functions such as print(), len(), and type(). Python makes everything inside "builtins" available globally. So we can use these functions without importing anything 🤷

  • graphical user interface, website

To view or add a comment, sign in

Explore content categories