Python use raw_input with a variable
Is it开发者_JAVA技巧 possible to use raw_input with a variable?
For example.
max = 100
value = raw_input('Please enter a value between 10 and' max 'for percentage')
Thanks,
Favolas
You can pass anything that evaluates to a string as a parameter:
value = raw_input('Please enter a value between 10 and' + str(max) + 'for percentage')
use + to concatenate string objects. You also need to explicitely turn non-strings into string to concatenate them using the str() function.
Python Language Reference, §5.6.2, "String Formatting Operations"
i think this might work
value = input('Please enter a value between 10 and {} for percentage'.format(max))
one more way to do it :)
value = raw_input('Please enter a value between 10 and %i for percentage' % (max))
精彩评论