+ 2

hey how can convert a='45' to b = 45

25th Oct 2016, 6:44 AM
Narendra Nairy
Narendra Nairy - avatar
8 odpowiedzi
+ 17
a = '45' b = int (a)
25th Oct 2016, 7:21 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 4
Nope you will get an int number a = '45' #single quotes makes it string so a is string now we will convert a from string to int b = int (a) You will get an int b = 45 ---------------- You will get ascii number if you use this function "ord" Print ("A = ", ord("A")) Output will be A = 65
25th Oct 2016, 7:49 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 1
You are Welcome :)
25th Oct 2016, 7:54 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 1
use b= int(a)
27th Oct 2016, 3:15 AM
Naveen Singh Negi
Naveen Singh Negi - avatar
+ 1
you have to cast the argument to convert a string to integer. b=int (a)
1st Dec 2016, 8:40 PM
Francisco Javier Coenda
Francisco Javier Coenda - avatar
0
thanks for your information
25th Oct 2016, 7:52 AM
Narendra Nairy
Narendra Nairy - avatar
0
here, when a='45' means that a has a string stored in it. to convert a string '45' to an integer 45 and to store it in a variable b ,we assign a variable b as an integer and copy the value of a to b. here typecasting occurs. b=into(a)
18th Jan 2017, 4:16 AM
vaishali
vaishali - avatar
- 2
i will not get it as b= 45. instead i might get b= some ascii number in related with '45' in int datatype
25th Oct 2016, 7:25 AM
Narendra Nairy
Narendra Nairy - avatar