0

Why the output is like this?

a=8 b=4 c=a/b d=str(c) print(2*d) I know the result is 2.02.0 but I have no idea why I thought it should be 4

19th Nov 2019, 6:39 PM
THEGreatGatsby
THEGreatGatsby - avatar
3 Respuestas
+ 6
In python print(n*string) will print it n times concateneted
19th Nov 2019, 6:44 PM
Saurabh B
Saurabh B - avatar
+ 6
See comments in the code: a=8 b=4 c=a/b # divide 8 / 4 = 2.0 division always creates a float d=str(c) # convert float to string = '2.0' print(2*d) # print 2 times '2.0' = '2.02.0'
19th Nov 2019, 6:48 PM
Lothar
Lothar - avatar
+ 1
I think it's python... c=2.0 as / will give float whereas // gives int division... Then d will be "2.0" Then 2*d is same as "2.02.0"
19th Nov 2019, 6:43 PM
Saurabh B
Saurabh B - avatar