Methods and Functions
sqrt() (square root) function really doesn’t have an object to apply to—we just pass a parameter to it—but it has to be defined in a class somewhere, so we make it a static method in the class
Math so that we can have something to use to call it.
01:11 While Python is object capable, it doesn’t require you to write things with objects and classes, which means the notion of functions is allowed! So absent of any class, any object, I can create a function! So, let me do it here.
and we’re just going to print the word
"Hi". A simplified version of Python’s “Hello, World” program. And without an object—I’ve not created an object, I don’t have a class—I can call this function simply by referring to it by name. And there it is!
02:24 This isn’t something that we can do in Java. In Java, everything has to be defined in a class. In Python, we can define functions anywhere that we want. In fact, many Python programs exist not making use of a single class or an object.
02:43 Everything they do is done in terms of functions. And so there’s another feature of Python that you don’t get to see in Java. In your next lesson, we’re going to start taking a look at the idea of inheritance and how that’s implemented in Python.
Become a Member to join the conversation.