Python中如何将raw_input与变量一起使用
可以用一个变量来配合raw_input吗?
比如说:
max = 100
value = raw_input('Please enter a value between 10 and' max 'for percentage')
谢谢,
Favolas
4 个回答
1
我觉得这个可能有效
value = input('Please enter a value between 10 and {} for percentage'.format(max))
10
你可以把任何能变成字符串的东西当作参数传递:
value = raw_input('Please enter a value between 10 and' + str(max) + 'for percentage')
用 + 来连接字符串对象。如果你想把不是字符串的东西连接成字符串,记得要用 str() 函数把它们转换成字符串。