+ 1

How to just declare variable without providing any value

26th Aug 2017, 3:42 AM
Akshay Priyadarshi
Akshay Priyadarshi - avatar
5 Réponses
+ 4
var = None Python is dynamic, so you don't need to declare things; they exist automatically in the first scope where they're assigned. So, all you need is a regular old assignment statement as above. This is nice, because you'll never end up with an uninitialized variable. But be careful -- this doesn't mean that you won't end up with incorrectly initialized variables. If you init something to None, make sure that's what you really want, and assign something more meaningful if you can.
26th Aug 2017, 5:14 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 2
varName = None
26th Aug 2017, 3:53 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I think what you may want is: x = int(input("Input a number")) print() if x % 2 == 0: print("No. is even") else: print("No is odd")
26th Aug 2017, 5:22 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
The Python function 'input()' produces a string, even if you enter an integer. You have to convert it to an integer (or a float) before you can put it in a mathematical formula. if you replace: x = 2 input(x) with just: x = input(int()) your code will work.
26th Aug 2017, 7:15 AM
David Ashton
David Ashton - avatar
0
but when i perform operation on this variable it shows an error https://code.sololearn.com/c4R241V1myz9/?ref=app
26th Aug 2017, 4:13 AM
Akshay Priyadarshi
Akshay Priyadarshi - avatar