How can i use raw_input and string formatting % or %d python

前端 未结 3 872
Happy的楠姐
Happy的楠姐 2021-01-26 11:26

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         


        
相关标签:
3条回答
  • 2021-01-26 11:42

    I guess the cleanest way is to use format:

    z = raw_input("Is your age {0}?".format(var))
    
    0 讨论(0)
  • 2021-01-26 11:45

    With raw_input, %var should also lie within the parentheses. i.e:

    z = raw_input("Is your age %d" % var)
    
    0 讨论(0)
  • 2021-01-26 12:02

    Your code should be:

    z = raw_input("Is your age %d" %(var,) )
    
    0 讨论(0)
提交回复
热议问题