+ 7
can anyone help me how to declare variable in python and assign value to a variable of particular data type
3 Réponses
+ 2
First you must understand that python is not like c++...when when you what to store a data in a variable you can simply assign the value.
eg: a=2
but to store string,you should give the data in double quotes
eg:a="my name is jim"
0
To declare a variable, you just create a separate line.
for ex: x as a integer
x = int(5) or x = int(input())
If it is a string make it str() instead of int()
Same with float()
0
Actually, you can't give type (not really) to a variable, as it could completely change in your programme.
If you want to use types, you should probably look for something like the typing module or RPython...