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

  • Home
  • SEARCH
  • 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 6330725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:55:24+00:00 2026-05-24T17:55:24+00:00

sorry if this is an obvious question, but I am relatively new to python

  • 0

sorry if this is an obvious question, but I am relatively new to python and am completely stumped at the moment. I am having difficulty getting my variables to work the way I want them too in a program I am working on.

Here is an example I quickly made to showcase my problem:

life = 200

def example(dudeHP):
    dudeHP = dudeHP - 75
    print (dudeHP)

example(life)
print (life) #output is 200, but I want it to be 125

As you can see, I am trying to get the value of the global variable “life” to change inside the def example codeblock with dudeHP (which would be a local variable if I am not mistaken?)

Is this viable? Is there a better way to accomplish this? Or am I doing it all wrong? Thankyou in advance 🙂

  • 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-05-24T17:55:25+00:00Added an answer on May 24, 2026 at 5:55 pm

    Well, first of all, you’ll probably want to write an class or something to organize all this at some point. Modifying global variables from within functions or methods is usually considered a bad idea.

    What you might want to try is this:

    life = 200
    
    def example(x):
        return x - 75
    
    life = example(life)
    

    Of course in this case the operation of subtraction is so trivial that you don’t need to encapsulate it in a function.

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

Sidebar

Related Questions

Sorry if this question seems obvious for everyone, but I am very new to
First of all, sorry if this is an obvious question, but I'm rather new
Sorry if this is a really basic question but it's been really getting to
Sorry if this is an obvious question, but I've found surprisingly few references on
Sorry if this is a question with a obvious answer but my knowledge with
I'm sorry if this is an obvious question but neither Google or a search
I am still new to MVC, so sorry if this is an obvious question:
Sorry if this is an obvious question, but my knowledge of asp.net is a
All Sorry if this is an obvious question but does WCF streaming work correctly
Sorry, this seems like such an obvious question, but I just can't find an

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.