Knowee
Questions
Features
Study Tools

what is the output of following python code? class myclass:    def display(self,a):        print(a)o=myclass()o.display("Hello World")

Question

what is the output of following python code? class myclass:    def display(self,a):        print(a)o=myclass()o.display("Hello World")

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given Python code will be:

Hello World

Here's the step by step explanation:

  1. A class named 'myclass' is defined.
  2. Inside this class, a method named 'display' is defined which takes two parameters: 'self' and 'a'. 'self' is a default parameter in Python which refers to the instance of the class and 'a' is a user-defined parameter.
  3. Inside the 'display' method, the value of 'a' is printed.
  4. An object 'o' of the class 'myclass' is created.
  5. The 'display' method is called on the object 'o' with the argument "Hello World". This argument is passed to the 'display' method as the parameter 'a'.
  6. The 'display' method prints the value of 'a', which is "Hello World".

This problem has been solved

Similar Questions

What is the output of the following code?        python    class A:        def display(self):            print("Class A")    class B(A):        def display(self):            print("Class B")    class C(A):        def display(self):            print("Class C")    obj = B()    obj.display()    obj = C()    obj.display()

what is the output of following python code? class myclass:    def __init__(self,a):        self.a = a        print(self.a)o=myclass()

What will be the output of the following Python code?class Demo: def __init__(self): self.a = 1 self.__b = 1  def display(self): return self.__b obj = Demo()print(obj.__b)

What will be the output of the following Python code?class fruits: def __init__(self): self.price = 100 self.__bags = 5 def display(self): print(self.__bags)obj=fruits()obj.display()

What is the output of the following code?     class Parent:        def show(self):            print("Parent")    class Child(Parent):        def show(self):            print("Child")    obj = Child()    obj.show()

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.