Reputation: 6147
Is there a one liner in python that will give me the same result as below? All I need to supply is a int value and then it return a string using @.
results in a string with '@' appended for each loop.
padding = ''
for x in range(5):
padding += '@'
print padding
Results:
@@@@@
Upvotes: 1
Views: 884
Reputation: 16136
If this is in the middle of some other formatting, you might use something like:
'{:@<{}}'.format('', 5)
(the inner {}
expands to 5
before the outer formatting applies)
Upvotes: 1
Reputation: 96246
Yes, strings are sequence types, so the easiest way is:
print '@'*5
Upvotes: 4