How to make variables with name of functions in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to make variables with name of functions in python

Recently I was working on a code myself where i needed to make a variable called class but i couldn't do it because it was throwing an error Can anyone tell me if it's possible to make variables such as print, if etc...

19th Dec 2022, 4:07 PM
Arin
Arin - avatar
6 Answers
+ 3
sure you can you can make it with underscore but putting undeescore before variable name can mean a private variable etc..but why would you want a variable called class
19th Dec 2022, 5:07 PM
Ion Kare
Ion Kare - avatar
+ 2
It is not a good thing if you overwrite the built-in keywords. How would you access them if you need to use them in their original purpose later? It is a necessary restriction.
21st Dec 2022, 8:22 AM
Bob_Li
Bob_Li - avatar
+ 1
class is a reserved identifier which is used to make class so you cannot use it as a variable
19th Dec 2022, 4:18 PM
A͢J
A͢J - avatar
+ 1
Bob_Li thanks I understood
21st Dec 2022, 2:40 PM
Arin
Arin - avatar
0
A͢J isn't there any way to use other things like functions as variable names?
19th Dec 2022, 4:38 PM
Arin
Arin - avatar
0
Ion Kare thanks for help I was just trying to code some random things and then tried to use class as variable but it didn't work so i just used cls insted
19th Dec 2022, 5:15 PM
Arin
Arin - avatar