Python Forum
"NameError: name 'catName1' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"NameError: name 'catName1' is not defined
#4
(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
3
You 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 C
I 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.
Reply


Messages In This Thread
RE: "NameError: name 'catName1' is not defined - by perfringo - Jun-24-2019, 06:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation NameError: name 'score' is not defined - Help? MrKnd94 13 5,246 Mar-06-2023, 10:54 PM
Last Post: deanhystad
  How to correct the NameError: name 'xx' is not defined? vokoyo 5 11,593 Feb-17-2021, 05:55 AM
Last Post: delonbest
  NameError: name 'os' is not defined, & load_files(sys.argv[1]) AryaIC 3 4,922 Nov-07-2020, 07:45 PM
Last Post: jefsummers
  Error in code NameError: name ' ' is not defined ppman00 11 6,729 Sep-18-2020, 05:22 AM
Last Post: ndc85430
  NameError: name 'print_string' is not defined jamie_01 2 2,149 Jun-11-2020, 05:27 AM
Last Post: buran
  NameError x not defined Bruizeh 5 5,520 Feb-27-2019, 10:59 AM
Last Post: Larz60+
  NameError: name 'mailbox_list' is not defined pythonnewb 2 4,857 Aug-06-2017, 09:31 PM
Last Post: pythonnewb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020