python之格式化输入或输出

  • 格式化输入:

input_value = input("普通文本[%s]:" % (var))    # []:可省略,需要时可用,如提醒用户还剩下几次输入次数时.%s:可为任何字符占位;%d:只能够为数字占位;
  • 格式化输出:

output_value = print("普通文本[%s]" % (var))    #print默认动作,在输出文本末尾加一个换行符\n


猜你喜欢

转载自blog.51cto.com/14258683/2375300
今日推荐