+ 7

can anyone help me how to declare variable in python and assign value to a variable of particular data type

25th Sep 2016, 5:20 PM
Athul Joy
Athul Joy - avatar
3 Answers
+ 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"
26th Oct 2016, 12:07 PM
Jim Joseph
Jim Joseph - avatar
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()
25th Sep 2016, 5:51 PM
Sarah
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...
25th Sep 2016, 9:23 PM
Amaras A
Amaras A - avatar