+ 15

print can be a name of a variable?

python question

12th Jul 2018, 7:35 PM
Numpy
Numpy - avatar
26 odpowiedzi
+ 9
You could have tried doing it in code playground.
13th Jul 2018, 8:15 PM
Mitali
Mitali - avatar
+ 8
Ben Allen (Njinx) check this out https://code.sololearn.com/c561KbRLt2f4/?ref=app
12th Jul 2018, 9:43 PM
Psychoalphadiscobetabioaquadoloop
Psychoalphadiscobetabioaquadoloop - avatar
+ 7
i ask for print only ?
12th Jul 2018, 7:52 PM
Numpy
Numpy - avatar
+ 7
we can name a variable print, but we canot after use print to appear some thinks, solution is to use del print , and if you try more to zrite del print , pytjon send to you print is note defined, the standar print is a callable object , you can make sure by callable(print) and you reciev True , if you name some think not callable print , now the callable (print) appe ae False , finally , print ,input,bool,chr,ord ,eval, callable, isinstance ,all functions and class ,we can use they name as a name of our variable, but we lose the function or class that we take her name.
13th Jul 2018, 3:20 AM
Numpy
Numpy - avatar
+ 3
yes, but you won't be able to use print to output something.
12th Jul 2018, 8:22 PM
Psychoalphadiscobetabioaquadoloop
Psychoalphadiscobetabioaquadoloop - avatar
+ 3
4G3N7 No. print is a reserved keyword, it won't work as a variable name.
12th Jul 2018, 8:53 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 3
def print(*args, **kwargs): pass print('hello world')
12th Jul 2018, 9:01 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 3
4G3N7 Huh, I stand corrected. I still wouldn't recommend actually doing this.
12th Jul 2018, 10:47 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 3
print is only a reserved word in Python 2, Python 3 changed it to a function, which is essentially a variable you can call. So yes, you can create a variable called print and even replace the default function in Python 3.
12th Jul 2018, 11:49 PM
Blake Quake
Blake Quake - avatar
+ 1
yes you can do.this code will help you. # to print all the local variables for i in locals().keys(): print(i) # to print all the global variables for i in globals().keys(): print(i)
13th Jul 2018, 12:34 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
reserved words can not be used cuz it's compiler's. you can add a number or _ at the last of it. examples: print5, print_, print____
14th Jul 2018, 7:59 AM
Ahmed Samir
Ahmed Samir - avatar
+ 1
no
14th Jul 2018, 11:32 AM
tardigrade
tardigrade - avatar
+ 1
the print method is a reserved word. Unless you modify print as print_,or print1 or another variable name #print2 it will create its own object, but print cannot be an Object variable itself.
15th Jul 2018, 2:34 AM
Apple Blossom
Apple Blossom - avatar
0
no,as it is a reserved keyword of python script
13th Jul 2018, 1:22 PM
Akash Verma
0
yes it can be a variable name but you need to change some of it's letters like : Print = 0 print_ = 0 PRINT = 0 and so on !
13th Jul 2018, 3:26 PM
Ahmad Muhammad
Ahmad Muhammad - avatar
0
print is a function is a reserved word will always this name print becouse its define in python api now variable can be the name you like following the names rules
13th Jul 2018, 6:18 PM
Neo
Neo - avatar
0
No. Print is a reserved word
14th Jul 2018, 12:30 PM
Natalie
Natalie - avatar
0
No
14th Jul 2018, 4:31 PM
Holmi Dligua
Holmi Dligua - avatar
0
No you can't use Print
15th Jul 2018, 5:28 PM
Manoj Shelgoankar
Manoj Shelgoankar - avatar
0
no
15th Jul 2018, 5:52 PM
Aditya Shrikant Kadam
Aditya Shrikant Kadam - avatar