Python的input功能不能直接做到这一点; 但您可以截断返回的字符串,或重复直到结果足够短.
# method 1
answer = input("What's up, doc? ")[:10] # no more than 10 characters
# method 2
while True:
answer = input("What's up, doc? ")
if len(answer) <= 10:
break
else:
print("Too much info - keep it shorter!")
Run Code Online (Sandbox Code Playgroud)
如果那不是您要求的,那么您需要更具体地提出您的问题.
| 归档时间: |
|
| 查看次数: |
12859 次 |
| 最近记录: |