Issue
i couldn't figure out how to write this another way (or should i say a more current way, like with an f-string or str.format). the goal is to print "Current activity" followed by dashes to a width of 26 characters as defined by a variable.
activityCols = 26
print("Current activity".ljust(activityCols,"-"))
any thoughts on a more current way?
i tried
activityCols = 26
print('{:-<(activityCols)}'.format("Current activity"))
but that didn't work.
Solution
.ljust
method is good enough,
If you want to try something new
original_string = "Current activity"
length = 26
character_to_append = "-"
result_string = f"{original_string:{character_to_append}<{length}}"
print(result_string)
Answered By - nilbarde
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.