Obtaining User Input

2 minutes
Share the link to this page
Copied
  Completed

Just as a data value can be assigned to a variable in a Python script, a user-specified value can be assigned to a variable with the Python input() function.

This accepts a string within its parentheses that will prompt the user for input by displaying that string then wait to read a line of input.

User input is read as a text string, even when it’s numeric, and can be assigned to a variable using the = assignment operator as usual.

The value assigned to any variable can be displayed by specifying the variable name to the print() function –to reference that variable’s stored value.

Multiple values to be displayed can be specified to the print() function as a comma-separated list within its parentheses.

  Download

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.