【发布时间】:2014-02-08 15:08:36
【问题描述】:
在 python 程序中,我有
...
wf = raw_input("enter string \n")
wl = list(wf)
wd = wl[:-4]
#now I want to see if wl is over 20 characters
#if it is, I want it truncated to 20 characters
#if not, I want character appended until it is 20 characters
#if it is 20 characters leave it alone
...
请帮助评论的东西按照它所说的去做
【问题讨论】:
-
这个问题似乎离题了,因为它是关于为你编写代码的。
-
@MaximeLorant 我无法确定要调用的特定函数以便可以附加 0。我尝试了一些不同的方法,但它们不起作用。没听说过str的zfill属性,也没听说过rjust/ljust。在我拥有的有关 Python 的书中没有提到它们。
标签: python list python-3.x truncate