[SOLVED] What is the simplest way to call a function in python? Where do we use classes and where do we use methods and where do we use methods within a class

Issue

Here is my code. What is the simplest way to call the example function?

class Sample():
    def example(x, y):
        z = x + y
        print(z)
        return z

I would really appreciate a nice description of it.

Solution

You can call it directly:

Sample.example(1, 2)

Answered By – Sean Xie

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.