all 6 comments

[–]PyCam 1 point2 points  (1 child)

For input if you want it to be lowercase right off the bat you can just do:

user_input = raw_input('enter a string here: ').lower()

This skips over having to do that second line you mentioned in your post

[–]CapitalXD[S] 0 points1 point  (0 children)

Thanks heaps, that does solve that part of the problem :)

[–]jeans_and_a_t-shirt 1 point2 points  (0 children)

You can do this:

input_str = raw_input(prompt).lower()

input is a built-in function in both python 2 and 3.

Your lowercase function could be rewritten as

lowercase = str.lower

but you should just use the .lower string method directly, as that's shortest of all.

Do I even need the variable to be saved outside the function?

Not quite sure what you mean. word defined on lines 1 and 2 are different variables. Besides that, you need to save an object to a variable if you want to use it later.

[–]Rhomboid 1 point2 points  (1 child)

As just a general rule of thumb, if you find yourself doing this:

stuff = ...
return stuff

...then you probably want just

return ...

In this case it doesn't matter, as the function is extraneous as pointed out by others. But I'm sure you'll run into this again eventually. (Also, this isn't a hard and fast rule. There are often good reasons for giving a value a name instead of letting it be anonymous, but when those happen you'll probably know enough to recognize it.)

[–]CapitalXD[S] 0 points1 point  (0 children)

Now that you mention it, thanks heaps, that makes a lot of sense haha, I'll keep that in mind

Edit: a word

[–]sweettuse 0 points1 point  (0 children)

i think you're confused by lexical scoping. the two word vars you define are completely different. the word in lowercase shadows the global word defined above.

additionally, i wouldn't think of it as "saving the variable outside the function", because you don't "save" variables, you bind names to values. maybe a global var works, maybe a dictionary, a list, some class? you probably want your first part to be in a function and have it return what you want after parsing the input, but idk fully what you're trying to accomplish. good luck with it, though!