0
Is string variable convert into integer or float?
A = "55" B = int(A) Print(B) Output: 55 But , A= "Ram" B= int(A) Print(B) Output: Error
10 Answers
+ 2
Mention the programming language also, cause every language behave differently.
+ 2
From the output this is obvious that Python can't convert a string that contains letters to an integer.
If you have numbers in string then it will work. and of course it will convert it to integer not the float.
for that you need to use - float(B)
while using int() for float value will only give error.
A = '12.0'
A = int(A)
print(A) # error because we have float value as a string
+ 1
Chintala Santhosh Char, Int & Float are represented differently in memory & act differently in a program. Every programming languages has its own way of handling this.
https://www.quora.com/What-is-the-difference-between-int-char-and-float
+ 1
Okay thank you I will check with your link
+ 1
Chintala Santhosh Sure, good luck đ
+ 1
Hey, yes this is python. And actually the problem isn't so much in how you coded it, but that int will only work on whole numbers. Hope this helps.
0
Thank sir thank you so much
0
Actually my question is Why numbers not characters ....
Is Python works like this only
0
I am new to programs this is my first program don't hesitate with my questions