by EdwardDiego · 2y ago · 0 comments
Only context I've ever found it useful in, is if you're unit testing something that accepts a string of max length M, then
bad_str = "A" * (M + 1)
Is quite nice and also, easy to interpret.But if you're calling multiply on a list[list[Any]] lol nah mate, what the hell are you playing at, make a for loop and add comments.
It's also remarkebly easy to diagnose once you see the unexpected behaviour, so anyone asking for help is going to be instantly told not to do it and use a comprehension instead.
I'm sure there are plenty of other pitfalls in other languages, though I concede this one is especially unintuitive to a new person.
On a mutable sequence. Or anything mutable. [] being a sequence is not the issue here.
If you work with immutable stuff, * is really not an issue.
'a'*3 == 'a'+'a'+'a'