Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Reading User Input From the Keyboard With Python (Summary)

Now you have a comprehensive understanding of handling user input in Python, and you’ve explored various techniques and modules to enhance your interactive programming skills.

You started by delving into the basics, using the input() function to collect user input and exploring methods to ascertain and manipulate the data types. This foundational knowledge is crucial for creating versatile programs that can adapt to diverse user inputs.

Moving on, you practiced error handling strategies, ensuring your programs gracefully handle unexpected inputs, enhancing user experience and program robustness. You then used the getpass module, offering a secure way to accept sensitive information such as passwords without displaying them on the screen.

You now can model real-life entities like banks and craft intricate, interactive programs with multiple answers right in your terminal. This knowledge opens the door to creating engaging, user-friendly applications that respond intelligently to user input, providing a solid foundation for your journey into Python programming.

Resources mentioned in this lesson:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

00:00 In the previous lesson, I demonstrated the getpass() function. In this lesson, I’ll summarize the course and point you at other content.

00:08 Python’s built-in input() function gets used to fetch a response from the user. It always returns a string, which means you may need to convert it to an integer or float if that’s what you want in your program.

00:20 You can do this conversion by calling the corresponding int() or float() constructors.

00:25 One way of accepting multiple values of input is to parse a string using its .split() method. You saw how to parse comma-separated values with this approach. When dealing with user input, especially if you need to compare it to an expected answer, you may want to clean it.

00:41 The string’s .strip() method removes leading and trailing whitespace, while its .lower() method returns a string that’s all lowercase.

00:50 There’s also a corresponding .upper() method if you need to go in that direction instead. If you need sensitive input from the user and don’t want their response echoed to the screen, instead of calling input(), you can use the getpass() function from the module of the same name.

01:06 There’s always more content at Real Python. This course was based on a written tutorial. The tutorial covers one thing I did not: a third-party library called PyInputPlus.

01:16 This library has functions that help you ask for input, like automatically re-prompting a user when their input is invalid. If this is something that interests you, you might want to check out the last section of the tutorial.

01:29 Since PyInputPlus is a third-party library, you need to know how to handle virtual environments, as you should never install a package without one.

01:38 In case that topic’s new to you, well then check this course or tutorial out before playing with PyInputPlus or any other third-party package.

01:48 This course was all about the input() function, which is one of many built into Python. For a complete list and tutorial around all built-in functions, check this content out.

01:59 That’s all for now. I hope you learned something useful. Thanks for your attention.

Become a Member to join the conversation.