MediumProgramming
What does Python print for fancy(3, '.') when default arguments are used?
TL;DR
It prints
.*.*.*..Question
What does this code print?
def fancy(length, char1='-', char2='*'):
return (char1 + char2) * length + char1
print(fancy(3, '.'))
Explanation
In fancy(3, '.'), length receives 3, char1 receives a full stop, and char2 keeps its default value, an asterisk.
The pair .* is repeated three times, giving .*.*.*. A final full stop from char1 is appended, producing .*.*.*..
Platforms
- Stepik
