+ 1

Why this code doesn't work any_thing= 12 print("the best person is " + any_thing )

any_thing= 12 print("the best person is " + any_thing )

14th Feb 2022, 2:09 PM
ZIZO Abd alkawy
6 Answers
+ 5
ZIZO Abd alkawy , you can do it also without converting : any_thing= 12 print("the best person is", any_thing)
14th Feb 2022, 5:04 PM
Lothar
Lothar - avatar
+ 4
Because any_thing is an integer type. You cannot concatenate string and integer like how you have tried. While printing do + str(any_thing)
14th Feb 2022, 2:15 PM
Avinesh
Avinesh - avatar
+ 3
any_thing= 12 print("the best person is " + str( any_thing))
14th Feb 2022, 2:15 PM
NEZ
NEZ - avatar
+ 1
Avinesh NEZ thanks
14th Feb 2022, 2:20 PM
ZIZO Abd alkawy
+ 1
12 is an integer, "the best person is " is a string, You cannot concentrate these together without converting 12 to a string which can be done with str(any_thing) You can also use f-strings. print(f"the best person is {any_thing}") (the f before the " is required)
17th Feb 2022, 1:02 AM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
0
Semicolon i think
15th Feb 2022, 10:14 AM
Bharath