方法ljust/rjust/center

dict = {'apple':4,'banana':10,'pear':8}

def printItem(dictName,leftwidth,rightwidth):
    print("Menu".center(leftwidth+rightwidth,'-'))
    for i,k in dictName.items():
        print(i.ljust(leftwidth,'.') + str(k).rjust(rightwidth))

printItem(dict,20,4)
----------Menu----------
banana..............  10
pear................   8
apple...............   4

Process finished with exit code 0

 

posted on 2017-09-03 16:43  winecork  阅读(98)  评论(0)    收藏  举报

导航