(Jun-22-2019, 06:23 PM)tofif Wrote: This was an example in my book, and this is what was stated:
def myfuncttion( parameter1, parameter2 ): return answer1, answer2, answer3 variable1, variable2, variable3 = myfunction(argument1, argument2)
Some add-on information to noisefloor and jefsummers comments.
For starters I suggest to learn meaning of parameters and arguments. Start with Python official FAQ What is the difference between arguments and parameters?
This function example (if it is full code) doesn't make sense. Function is defined with parameters but they are not used in function body.
Assigning names to function result however is quite standard practice and it's called unpacking. Function returns tuple and you can 'unpack' it by assigning names:
>>> def my_func(): ... return 1, 2, 3 ... >>> type(my_func()) tuple >>> one, two, three = my_func() >>> one 1 >>> two 2 >>> three 3You can make cat_names function to work in several ways. One of them is:
>>> def cat_names(): # you don't define parameters ... first = input('What was your first cats name: \n') ... second = input('What was your second cats name: \n') ... third = input('What was your third cats name: \n') ... return first, second, third # returns tuple with cat names ... >>> cat_one, cat_two, cat_three = cat_name() # unpack cat names, no arguments given What was your first cats name: A What was your second cats name: B What was your third cats name: C >>> cat_one A >>> cat_two B >>> cat_three C >>> print('My first three cats were named: {one}, {two} and {three}'.format(one=cat_one, two=cat_two, three=cat_three)) My first three cats were named: A, B and CI used .format method as you use Python 3.5. I suggest to upgrade your Python version to take advantage of f-strings. You probably observe that there is lot of repeated typing in questions, you can get rid of that but this probably not the topic while learning fundamentals.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.