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?

Recommended Answers

All 2 Replies

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.
x.celTofer(34)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.