i have variable var, and it is changeable
how can i use raw_input and inside raw_input
make a question and use this variable
i.e.
z = raw_input("Is your age %d') %(var)
but this don't work. Any ideas?
With raw_input
, %var should also lie within the parentheses. i.e:
z = raw_input("Is your age %d" % var)
I guess the cleanest way is to use format
:
z = raw_input("Is your age {0}?".format(var))
Your code should be:
z = raw_input("Is your age %d" %(var,) )
来源:https://stackoverflow.com/questions/24230069/how-can-i-use-raw-input-and-string-formatting-or-d-python