Python Forum
Printing the variable from defined function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing the variable from defined function
#1
Hi,

Quite new topython and this is a problem I have spent 1.5 hrs trying to work out, for context I wanted to define a function that would create a file named based on the variable input to the function. I have come across the issue that I am able to return the variable's value or the function define, but am not able to print the variable I am putting into the function.

I have given a brief example of what I mean- I would want the function to print 'a' if "function(a)" is ran. Thanks in advance, I'm sure there is a easy solution but searching forums/google has not got me beyond the .split('=')

a = 3

def function (input):
    print(f"{input}")
    print(f"{input=}".split('=')[0])

function(a)
Reply


Messages In This Thread
Printing the variable from defined function - by jws - Sep-02-2023, 05:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Variable not defined even though it is CoderMerv 3 355 Mar-28-2024, 02:13 PM
Last Post: Larz60+
  Variable for the value element in the index function?? Learner1 8 717 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 633 Nov-23-2023, 02:53 PM
Last Post: rob101
  Function parameter not writing to variable Karp 5 1,013 Aug-07-2023, 05:58 PM
Last Post: Karp
  Getting NameError for a function that is defined JonWayn 2 1,150 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,971 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,351 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,075 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  User-defined function to reset variables? Mark17 3 1,699 May-25-2022, 07:22 PM
Last Post: Gribouillis
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,200 Apr-05-2022, 04:55 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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