Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print variable name?
#12
It would be better to do it in a dictionary rather than a list:

POINTS = {'a': 5: 'b': 3, 'c': 7, 'd': 2, 'e': 1, 'f': 9}
Then the function is simpler:

def length(x, y):
    print(f'{x} = {POINTS[x]}')
    print(f'{y} = {POINTS[y]}')
    print(f'The length of {x}{y} is {POINTS[x] + POINTS[y]}')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
How to print variable name? - by mayadob - Oct-18-2019, 10:11 AM
RE: How to print variable name? - by mayadob - Oct-18-2019, 10:33 AM
RE: How to print variable name? - by Larz60+ - Oct-18-2019, 11:08 AM
RE: How to print variable name? - by mayadob - Oct-18-2019, 11:23 AM
RE: How to print variable name? - by perfringo - Oct-18-2019, 12:29 PM
RE: How to print variable name? - by mayadob - Oct-20-2019, 01:10 PM
RE: How to print variable name? - by mayadob - Oct-20-2019, 04:07 PM
RE: How to print variable name? - by mayadob - Oct-18-2019, 02:28 PM
RE: How to print variable name? - by ichabod801 - Oct-20-2019, 05:45 PM
RE: How to print variable name? - by ichabod801 - Oct-21-2019, 01:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print variable without '' and spaces arnonim 1 794 Jan-30-2023, 05:23 PM
Last Post: deanhystad
  Problem with print variable in print.cell (fpdf) muconi 0 725 Dec-25-2022, 02:24 PM
Last Post: muconi
  Remove a space between a string and variable in print sie 5 1,963 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Can you print a string variable to printer hammer 2 2,108 Apr-30-2022, 11:48 PM
Last Post: hammer
  Print variable between " paulo79 5 1,819 Mar-11-2022, 05:16 PM
Last Post: deanhystad
  When I print a key from dict it prints it but when I try to assign it to a variable I stefanvelikov 3 2,460 Nov-27-2020, 01:29 PM
Last Post: stefanvelikov
  Print variable values from a list of variables xnightwingx 3 2,739 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Print part of a variable rs74 4 2,706 Jul-27-2020, 04:39 PM
Last Post: rs74
  How do I print a returned variable calculated in another function? RedSkeleton007 3 3,675 Jul-10-2018, 12:10 PM
Last Post: buran
  Empty variable when using print before readline fstefanov 3 3,778 Oct-23-2017, 02:22 AM
Last Post: fstefanov

Forum Jump:

User Panel Messages

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