我正在尝试制作一个简单的小程序,告诉用户密码错误 但是当我希望程序带回他们输入的密码并说它是错的时候它不会让我。有人帮助我..
username = raw_input("Please enter your username: ")
password = raw_input("Please enter your password: ")
fail1 = raw_input("Your password is very insecure, make a new one: ")
print "Your password [password] is too weak!"
答案 0 :(得分:3)
Python不会神奇地格式化字符串,您需要明确地 :
print "Your password {} is too weak!".format(password)
有关.format()
方法的工作原理的详情,请参阅Format string syntax。
或者,使用以下任何一种:
print "Your password", password, "is too weak!"
print "Your password %s is too weak!" % password
import string
template = string.Template("Your password ${password} is too weak!")
print template.substitute(password=password)
答案 1 :(得分:0)
如果要在另一个字符串中显示字符串,则需要使用%。例如:
print "Your password [%s] is too weak" % password
答案 2 :(得分:0)
尝试:
print "Your password %s is to weak!" % password
答案 3 :(得分:0)
print "Your password", password, "is to weak!"