Right Justify python

前端 未结 5 1925
失恋的感觉
失恋的感觉 2021-01-19 13:39

how can I justify the output of this code?

N = int(input())
case = \'#\'
print(case)

for i in range(N):
    case += \'#\'
    print(case)
5条回答
  •  一个人的身影
    2021-01-19 13:48

    Seems like you might be looking for rjust:

    https://docs.python.org/2/library/string.html#string.rjust

    my_string = 'foo'
    print my_string.rjust(10)
    '       foo'
    

提交回复
热议问题