Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
def vs class
#2
In your second piece of code, there are three errors -
  1. No : at the end of line 1
  2. On line 2, you seem to have forgotten an 'l' - it should be
    if x=='furball':
  3. On line 3, print shouldn't be having a capital p
However, anyways your code isn't expected to work as you just print Grumpy, not define it under a variable and call it, and so the expected error.
You can use this :
def Cat(x):
    if x=='furball':
      addition = 'Grumpy'
    return addition
 
print('Our latest addition:',Cat('furball'))
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Messages In This Thread
def vs class - by Nienie - Jul-02-2020, 11:58 AM
RE: def vs class - by pyzyx3qwerty - Jul-02-2020, 01:31 PM
RE: def vs class - by Larz60+ - Jul-02-2020, 02:56 PM

Forum Jump:

User Panel Messages

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