繁体   English   中英

我的字符串格式有什么问题?

[英]What's wrong with my string formatting?

所以我对 Python 完全陌生,到目前为止我只制作了 JS 和 PHP。

所以我有这个代码

    """Shutdown code"""
timeToShutdown = input("Time to shutdown: ")

import os

os.system("shutdown /s /t %d") % timeToShutdown

它不能那样工作(不做任何事情),

它只能这样工作

"""Shutdown code"""
#timeToShutdown = input("Time to shutdown: ")

import os

os.system("shutdown /s /t 7200")

那么输入数字作为变量有什么问题。

PS:我也试过int(input())

您必须格式化字符串,而不是返回值。 即,将您的%移到括号内:

os.system("shutdown /s /t %s" % timeToShutdown)
                           ^ input() returns a string not a number

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM