How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask George Sibiya Your Own Question
George Sibiya
George Sibiya, Computer Hardware Engineer
Category: Programming
Satisfied Customers: 219
Experience:  PhD in Computer Science
94470076
Type Your Programming Question Here...
George Sibiya is online now
A new question is answered every 9 seconds

OKPR99211 I am learning Python and trying to better

This answer was rated:

OKPR99211 I am learning Python and trying to better understand classes. In this simple example, why does the last statement, print D, not return, C = 3, and how would I access the variable C in other parts of my program? I am trying to understand how to create and modify variables inside a classes methods and then access those variables in other parts of my program. Thanks for helping me understand this issue. class Obj: A = 1 def __init__(self): B = 2 def tran(self): C = 3 this = Obj() D = this.tran() print D

Hi,

Welcome to JustAnswer and thank you for utilising our services

Please try return D instead of print D because that is what print does

Regards,

G

Customer: replied 1 month ago.
What if i wanted to access multiple variables, can i return multiple

You'd need a function which returns the variable for each variable

George Sibiya and other Programming Specialists are ready to help you