Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Input Methods Tutorial, Lecture notes of Computer Programming

A tutorial on how to take input in Python using the input() and raw_input() functions. It explains how these functions work and provides examples of their usage. It also explains how to check the Python version. likely to be useful as study notes or lecture notes for a Python programming course.

Typology: Lecture notes

2021/2022

Available from 10/27/2022

tantan-bernabe
tantan-bernabe 🇵🇭

5 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Program Tutorial
University of the Philippines
How to take input in Python
Certain input is a way of interacting with the user or retrieving data to provide results. Python provides
two built-in methods for reading data from the keyboard. These methods are shown below.
- input(prompt)
- raw_input(prompt)
input()
Input functions are used in all recent versions of Python. Takes input from the user and evaluates
expressions. The Python interpreter automatically detects whether the user has entered a string,
number, or list. Let's understand the following example.
Example 1
Output:
The Python interpreter will not execute further lines until the user enters the input.
Let's understand another example.
Example 2
pf3
pf4

Partial preview of the text

Download Python Input Methods Tutorial and more Lecture notes Computer Programming in PDF only on Docsity!

Python Program Tutorial University of the Philippines How to take input in Python Certain input is a way of interacting with the user or retrieving data to provide results. Python provides two built-in methods for reading data from the keyboard. These methods are shown below.

  • input(prompt)
  • raw_input(prompt) input() Input functions are used in all recent versions of Python. Takes input from the user and evaluates expressions. The Python interpreter automatically detects whether the user has entered a string, number, or list. Let's understand the following example. Example 1 Output: The Python interpreter will not execute further lines until the user enters the input. Let's understand another example. Example 2

Output: Explanation: By default, the input() function accepts input as a string. So if you need to provide an input of type Integer or Float, you have to cast the input() function to that type. How input() function works?

  • Program flow stops until the user provides input.
  • Text statements, also known as prompts, can optionally appear in the input() function. This prompt - prints a message to the console.
  • The input() function automatically converts user input to a string. You have to explicitly convert the input using type casting.
  • raw_input() - The raw_input function is used in older versions of Python such as Python 2.x. Receives input from the keyboard and returns it as a string. Python 2.x is not widely used in the industry. Let's understand the following example. Example Output: How to check Python version? To check your Python version, open a command line (Windows), shell (Mac), or terminal (Linux/Ubuntu) and run python - version. The corresponding Python version is displayed.

Let's have a look at following image.