Resolve a quoted variable in a function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Resolve a quoted variable in a function

z=100 def prnt(x): print('x= :'+str(x)) prnt(z) I wrote the above code whose output is x= :720 But instead of x= :720, I want print z= :720. How to resolve x inside a quote?

30th Jul 2017, 9:10 AM
Arunansu
5 Answers
+ 1
you should change 'x= :' in 'z= :" if you want be able to change the letter just add another parameter to the function in which is specified the variable's name
30th Jul 2017, 10:19 AM
Matte
Matte - avatar
+ 1
and in the variable "z_name" you can put every name u want https://code.sololearn.com/c8yij0ulJj3z/?ref=app
30th Jul 2017, 1:41 PM
Matte
Matte - avatar
0
sorry, but can u give me an example? even if u put two parameters, the one inside the quote remains same, I guess.
30th Jul 2017, 1:23 PM
Arunansu
0
Great. Thanks. just curious, is there any way to resolve sth within quote? I used SAS till now. there u can resolve a macro, if it is kept within double quote. Like, %let z=h; %put "&z"; will give u - h, whereas %put '&z' will give u - &z.
30th Jul 2017, 3:05 PM
Arunansu
0
i don't know if there is any method, i'm not a professional programmer, i think you should ask to someone more capable than me, sorry :(
30th Jul 2017, 3:17 PM
Matte
Matte - avatar