0

What if you write: x = 12 \n x = x + 'string' \n print (x) ; is the output then "12string"?

Because it said that variables can be strings and integers. Can they be both at the same time?

25th Aug 2017, 3:00 PM
Leon Orou
Leon Orou - avatar
2 Antworten
+ 1
12 is a integer '12' is a string... int('12') is an intger similar to 12( string to int conversion) str(12) is a string similar to '12'(int to string conversion) x=12 x=x+'string' now x is int value 'string' is string 2 diff type of variables cant be added... WILL SHOW ERROR u can dooo x=12 x=str(x) + 'string' then its 12string as output
25th Aug 2017, 3:09 PM
sayan chandra
sayan chandra - avatar
+ 5
x="12" x=x+"string" print(x) will be 12string otherwise you will get an error
25th Aug 2017, 3:07 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar