0

How can I print userInputVariable from aFunction of class A into class B in bFunction in Python?

    @staticmethod
    def aFunction():
        userInputVariable = input("Enter string: ")
        print("This print function not should use in bFunction but print in aFunction while i call aFunction")
        
class B(A):
    def bFunction():
        #Here print userInputVariable
        pass

b = B()
b.aFunction()
#Now bFunction should run and print userInputVariable```

1 Answer 1

1
class A:
    @staticmethod
    def aFunction():
        userInputVariable = input("Enter string: ")
        print(userInputVariable)

class B(A):
    def bFunction(self):
        super().aFunction()


b = B()
b.bFunction()

super() method to invoke parent class methods and variables

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry i left something to add in question So, please give answer again after seeing question. I want use print() function while i call aFunction but not use print () function while call bFunction
Do you need to use the aFunction's variable inside bFunction?
Yes how can i do please help me
I have updated the answer, if this doesn't solve your problem, please explain the question clearly. @RaviCoder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.