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
3 Antworten
+ 6
In python print(n*string) will print it n times concateneted
+ 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'
+ 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"