Python Forum
Changing Variables within Variables?
Thread Rating:
  • 4 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing Variables within Variables?
#10
(Apr-21-2017, 02:14 AM)dave925 Wrote: Thanks for all your replies. To answer what I was doing that led to the question:

I started my program declaring my variables.

day, date, topic = '','',''


then I declared my title using the above variables....

title = day+date+topic

then, I started my program with a loop which altered the day, date, and topic, but I noticed that when I wanted to write the title, it was just blank because the variables weren't fluid within my variable declaration. I suppose, like you all are saying, I would need to declare my title as a List or Dictionary to make the variables modifiable.

Thanks again!

If you don't want to write title = day+date+topic inside whatever loop you're using, then you could write a small function like:

def get_title(day, date, topic):
    return "{0}{1}{2}".format(day, date, topic)
...and just use the function instead.  But having a string who's contents change depending on where you are in your program, is a pathway that leads directly to madness.
Reply


Messages In This Thread
Changing Variables within Variables? - by dave925 - Apr-20-2017, 05:38 AM
RE: Changing Variables within Variables? - by Kebap - Apr-20-2017, 04:33 PM
RE: Changing Variables within Variables? - by nilamo - Apr-26-2017, 05:19 AM
RE: Changing Variables within Variables? - by wavic - Apr-21-2017, 08:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 244 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  importing variables from module 8376459 1 309 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  Checking for Validity of Variables RockBlok 2 584 Dec-17-2023, 05:50 AM
Last Post: Gribouillis
  Create X Number of Variables and Assign Data RockBlok 8 1,039 Nov-14-2023, 08:46 AM
Last Post: perfringo
  mypy, type aliases and type variables tomciodev 1 754 Oct-18-2023, 10:08 AM
Last Post: Larz60+
  Unchangeable variables in a class? Calab 12 1,674 Sep-15-2023, 07:15 PM
Last Post: deanhystad
Question How create programmatically variables ? SpongeB0B 6 1,417 Aug-19-2023, 05:10 AM
Last Post: SpongeB0B
  How to store columns of a .csv in variables (when the .csv has no headers) ? hobbyist 6 1,361 Aug-18-2023, 02:06 PM
Last Post: deanhystad
  Variables in a SCPI string thomaswfirth 3 981 May-22-2023, 05:04 PM
Last Post: thomaswfirth
  Advancing Through Variables In A List knight2000 0 543 May-13-2023, 03:30 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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