I'm very new to Python and don't know very much about it's syntax and I need to write a class to interface with code given to me.

result = temperature(celsius=tempC).fahrenheit()

The class is a temperature class that converts from celsius to fahrenheit and vise versa. The thing that is causing me problems is the celsius=tempC in the class instantiation. How exactly does this work?

8 Years
Discussion Span
Last Post by willygstyle

It only means that the function __init__ in the class temperature (which is called at instantiation) has an optional argument 'celsius'. Follow this link for the use of optional arguments to functions.


You really shouldn't have to pass the variable in the return statement. It should be passed to the "method" inside your "object".
class temp(object): #temp is the object
def celTofer(self, cel): #celTofer is the method
print("I can use ", cel, " now") #if I am x I am 34, If I am y I don't exist yet, beacuase nobody told me what cel is :(

Build a class object first.
x = temp()
y = temp() #just for clarity
Now saying x is like saying temp()

Now call the method and pass it the variable.

Hopefully thats not to confusing but thats kinda how classes operate.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.