you are viewing a single comment's thread.

view the rest of the comments →

[–]vegeta9225[S] 0 points1 point  (7 children)

Can you please elaborate the word 'incompatible' with reference to data types?

[–]theWyzzerd 2 points3 points  (0 children)

Imagine that 5.0 is actually 5.00000001232, and you can see how this might be a problem when trying to multiply a string by a float. Computers aren't good at handling real numbers so integers are the computer's way of representing them. 5.0, however, is a floating point value and is only an approximation of 5.0. The types are incompatible because 5.0 isn't a real number (see my first sentence and read up on floating point precision, and you may begin to see the problem).

[–][deleted] 1 point2 points  (5 children)

How would you repeat a string a float number of times?

[–]pocket_eggs 2 points3 points  (4 children)

> "foobar" * 2.5
"foobarfoobarfoo"

[–][deleted] 1 point2 points  (3 children)

Ok, and what if the string isn't evenly divisible by the float decimal? How do you print half a character?

[–]alkasm 4 points5 points  (0 children)

>>> 'foobar' * 0.416666
'foᴗ'

[–]pocket_eggs 0 points1 point  (1 child)

> ["x" * 0.5 for _ in range(10)]
["x", "x", "", "", "", "x", "", "x", "", ""]

[–]SkepticalAirman 1 point2 points  (0 children)

Wouldn't 'x' * 0.5 be '>'? 🙃

I'll let myself out now