Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:12:41+00:00 2026-06-04T21:12:41+00:00

I have the below piece that created few person objects and apply some methods

  • 0

I have the below piece that created few person objects and apply some methods on those objects.

class Person:
    def __init__(self, name, age, pay=0, job=None):
        self.name = name
        self.age  = age
        self.pay  = pay
        self.job  = job

    def lastname(self):
        return  self.name.split()[-1]

    def giveraise(self,percent):
        return self.pay *= (1.0 + percent)

if __name__ == '__main__':
    bob = Person('Bob Smith', 40, 30000, 'software')
    sue = Person('Sue Jones', 30, 40000, 'hardware')
    people = [bob,sue]
    print(bob.lastname())
    print(sue.giveraise(.10))

Once I run this program, this is the output–

Syntax Error: Invalid syntax

but when I run using the below code, I don’t have any problem,

if __name__ == '__main__':
    bob = Person('Bob Smith', 40, 30000, 'software')
    sue = Person('Sue Jones', 30, 40000, 'hardware')
    people = [bob,sue]
    print(bob.lastname())
    sue.giveraise(.10)
    print(sue.pay)

What is the difference in two cases

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:12:42+00:00Added an answer on June 4, 2026 at 9:12 pm

    I get the invalid syntax error even in the second version; I don’t know how you got it to work, but you must have changed the giveraise function. In Python, assignments, including those using mutators like *=, are statements, not expressions; they have no value. Since they have no value, it doesn’t make sense to return them from a function, hence the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below code. <table> <tr> <td class=bgimg valign=middle width=10% title=some title nowrap> <img
I have inherited a piece of SQL that I am working on for a
All, I'm trying the code below, and I think that as I have written
I have a multi-part array that I want to grab a piece of and
I have an iPhone app problem that's been bugging me for a few days
I have 2 tables: Person and Item. I just created a new column in
I am creating objects on a line in a window created by this piece
I've got a short piece of code that originally created an SqlDataAdapter object over
I have a problem with a piece of legacy c++/winsock code that is part
I have a question here that looks a little like some of the ones

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.