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 8739947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:02:41+00:00 2026-06-13T11:02:41+00:00

I am trying to improve my existing code, is there any way to affect

  • 0

I am trying to improve my existing code, is there any way to affect multiples different variables without using dict or lists or tuples??
I am trying to write something like:

number1 = 1
number2 = 2
number3 = 3

for i in (1,2,3):
    number{i} += 1

and then have number1 = 2 number2 = 3 and number3 = 4

i was thinking about formatting string but it doesn’t work, thx for reading.

  • 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-13T11:02:42+00:00Added an answer on June 13, 2026 at 11:02 am

    A better approach here would be to use dictionary :

    In [26]: numbers={'number1': 1,
       ....:          'number2' : 2,
       ....:           'number3' : 3}
    
    In [27]: for i in (1,2,3):
       ....:         numbers['number'+str(i)]+=1
       ....: 
    
    In [28]: numbers['number1']
    Out[28]: 2
    
    In [29]: numbers['number2']
    Out[29]: 3
    
    In [30]: numbers['number3']
    Out[30]: 4
    

    otherwise you can also you globals():

    In [31]: number1 = 1
    
    In [32]: number2 = 2
    
    In [33]: number3 = 3
    
    In [34]: for i in (1,2,3):
       ....:     globals()['number'+str(i)]+=1
       ....:     
       ....:     
    
    In [35]: number1
    Out[35]: 2
    
    In [36]: number2
    Out[36]: 3
    
    In [37]: number3
    Out[37]: 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to improve some existing code which originally took 3 minutes to prepare
I am trying to improve an existing javascript levenstein distance calculation source code to
I'm trying to improve an existing solr search which uses the StandardRequestHandler. I'd like
I'm trying to improve FxCop compliance in my code (for the first time ever),
I've been trying to improve the build times for my product. We're using continuous
I am trying to improve performance by limiting my objects in memory by using
I am trying to improve SQLite error handling in an existing C++ program. I
I'm trying to improve an existing implementation of document displaying component. One of the
I'm trying to improve performance of an existing MySQL database. It's a database regarding
I trying to improve my skills using Try Catch blocks and better error handling.

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.