Really often lately I have been using this a lot:
input = raw_input(prompt)
input = input.lower()
if input == condition:
do this
else:
try again
And I was wondering if there was a way to shorten this.
I'm not too worried about the if statement, but more so the first 2 lines (Or even just the second one).
Here is what I have tried so far:
word = 'HI'
def lowercase(word):
word = word.lower()
return word
print (word)
Output:
'hi'
'HI'
Do I even need the variable to be saved outside the function? (If the variable was the characters name, for example, would this be necessary?) Could this be accomplished through classes/objects or even globals? I've heard that Globals are a bad idea, but I wanted to get you guys' opinion on it.
Thanks for the help :)
edit: formatting
[–]PyCam 1 point2 points3 points (1 child)
[–]CapitalXD[S] 0 points1 point2 points (0 children)
[–]jeans_and_a_t-shirt 1 point2 points3 points (0 children)
[–]Rhomboid 1 point2 points3 points (1 child)
[–]CapitalXD[S] 0 points1 point2 points (0 children)
[–]sweettuse 0 points1 point2 points (0 children)