+ 1
using variables from function
def yet(yut): yut="yaaah" return yut print(yut)uuu This code output is NameError: yut is not defined is there any way I can use variable yut outside function yet?
6 Respostas
+ 1
Still a newb but can’t you just declare it as a global variable?
0
Ben Bryant I've never heard those I'll look it up thanks
0
No prob. I think you just use the work ‘global’ before it. But they’re frowned upon for reasons I don’t yet understand 👍🏻
0
you can have def yet():
and print(yet)
0
Yes of course! Use the yet function as an output. This made my life a lot easier when trying to write a function that rolled a dice because I couldn’t get the dice roll out of the function and into the main code. Now I just assign the result of the func to a variable and call the variable
0
I'll experiment with these suggestions thanks