0

Adding a string to a number produces an error. Please give an example to illustrate it.

2nd Aug 2020, 4:03 AM
Sharad Kumar Mishra
Sharad Kumar Mishra - avatar
6 odpowiedzi
+ 4
we can't add strings with numbers because they both have different data types. But you can do by converting an integer into a string then add with strings. x=3 y="hello" print(str(x)+y) #output=3hello
2nd Aug 2020, 4:06 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Sharad Kumar Mishra sorry I edit my answer due to fast typing I write int(x) in print but it should be str(x)
2nd Aug 2020, 7:46 AM
Maninder $ingh
Maninder $ingh - avatar
0
Maninder $ingh but I have tried it you can also try by coding following code: print("7"+'string')
2nd Aug 2020, 4:27 AM
Sharad Kumar Mishra
Sharad Kumar Mishra - avatar
0
Maninder $ingh this wasn't my question but you are right in your way of understanding
2nd Aug 2020, 5:10 AM
Sharad Kumar Mishra
Sharad Kumar Mishra - avatar
0
Jan Markus thank you. Since I am begginner therefore I also have some minor confusion
2nd Aug 2020, 5:11 AM
Sharad Kumar Mishra
Sharad Kumar Mishra - avatar
0
Jan Markus I am not saying to you I am saying to Maninder $ingh
2nd Aug 2020, 5:35 AM
Sharad Kumar Mishra
Sharad Kumar Mishra - avatar