Python: How to pass an object into another class's parameter? -


I'm new to Python and I was trying to create a class that uses another object function Does, but I'm not sure how to do it. Any help is appreciated thanks!

So this is a difficult example of what I want to do

  class dog: def bark (self): print ( "Hello") square DogHouse: Def __init __ (Self, Dog): Self. = = Dog def bark2 (self): ???  

I want within Doghaus be able to call the bark of a dog, but I'm not sure how to do it correctly To do so.

What you are talking about is that I will give you a course in a university or a course However, I have taken a quick example to do this so that I think you want to do it:

  class A (object): def __init __ (self): print ( "Hello world") is a new word (a word, a few words): print (some_word.swapcase ()) @staticmethod def newer_print (some_word): Q Nt (some_word.lower ()) class B (object): def __init __ (self): print ("world") to make the object of class a # and then the method temp = A () temp.new_print ("this is an exam Is ") the static method of #call A.newer_print (" just another test ") __name__ ==" __main__ ": class B test = B ()  

for the object Note to # that there are two ways of class A (besides __init__ ). Before calling the first ( new_print ) method, the object of that class requires an object. Second ( newer_print ) can be run statically

Calling another class method is done either:

  1. Creating an object of the class and calling its methods or,
  2. Calling the static method

If you look at the immediate method of B, you will see that Two cases are displayed.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -