-2

I'm really new to Python but I'm trying to do something definitely above my skill level. Is it possible to calla a function though a variable? For example,

def one():
    print("this is a function")
progress = "one"
progress() 

with the intention of calling the function "one()".

Is this possible?

Ellian
  • 3
  • 1
  • `one` *is a variable*. `"one"` is not a function, it is a string. In python, functions are just objects like anything else. So of course, you can do `progress = one` – juanpa.arrivillaga Mar 26 '20 at 17:46
  • @MartijnPieters I'm not sure that's a good duplicate target, I think the OP simply wants `one = progress`, there has to be a more relevant question somewhere... – juanpa.arrivillaga Mar 26 '20 at 17:51
  • @juanpa.arrivillaga: that is not at all clear. They used a string, the other answer explains how to use a string to find and call a function. There simply multiple interpretations possible here, and so we can either close as 'unclear' or as a duplicate. The duplicate at least provides more information. – Martijn Pieters Mar 26 '20 at 18:01

1 Answers1

1

Just take off the double quotes around "one" and you should be good.

def one():
    print("this is a function")

progress = one
progress() 
dfundako
  • 8,022
  • 3
  • 18
  • 34