+ 1

Fix error in Python when i named a variable as print

I create a variable in Python named Print and when i use print function it shows an error , how to fix this problem without changing the Variable name.

26th Nov 2018, 9:49 AM
chandrapal singh
chandrapal singh - avatar
5 ответов
+ 5
D'lite Easy yes, but not good style. Rather use better describing variable names or extend them a bit. Like costume_print, myPrint, etc. Otherwise it's a likely error source, especially when it comes to multiple programmers or revisiting an old code
26th Nov 2018, 1:55 PM
Matthias
Matthias - avatar
+ 2
In general, don't use keywords as variables. Like print, class, etc...
26th Nov 2018, 10:01 AM
Matthias
Matthias - avatar
+ 2
chandrapal singh Easiest way to use reserved words is to change their case. example : if -> IF print --> Print https://code.sololearn.com/cdeElXd6S23S/?ref=app
26th Nov 2018, 10:14 AM
Dlite
Dlite - avatar
+ 1
I think in this case, your only solution is to use "namespaces" concept to be able to preserve your variable name.
26th Nov 2018, 9:52 AM
Geoffrey L
Geoffrey L - avatar
+ 1
D'lite , chandrapal seems to have changed the case already (the heading and the description are a little contradictory). The problem may also lie elsewhere. chandrapal singh , would you mind sharing your code so we can take a closer look? Thanks!
26th Nov 2018, 10:18 AM
Kishalaya Saha
Kishalaya Saha - avatar