![]() |
How to use a string method on user input - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to use a string method on user input (/thread-16849.html) |
How to use a string method on user input - Exsul - Mar-17-2019 while input("Hit Enter or type \"stop.\" ") != "stop":I'm trying to make it so that it doesn't matter if the user capitalizes "stop" or puts it in all caps. I've tried while input("Hit Enter or type \"stop.\" ") != str.lower("stop"):but that doesn't seem to do anything. I've also tried while input(str.lower("Hit Enter or type \"stop.\" ")) != "stop":but that just makes the prompt lower case. Help? RE: How to use a string method on user input - ichabod801 - Mar-17-2019 You use string methods on a string, not the str type. while input("Hit Enter or type \"stop.\" ").lower() != "stop":Since input returns a string, you can put it to the right of the input call, and it will apply to the return value of input. RE: How to use a string method on user input - Exsul - Mar-17-2019 (Mar-17-2019, 08:09 PM)ichabod801 Wrote: You use string methods on a string, not the str type. Perfect! Thank you. |