top of page

Python - Input data



So far, we have written programs that performed calculations and displayed the results on the screen. The programs worked without any interaction with the user. In this article, we will learn how to enable two-way communication so that the user can provide data to the program, and the program can respond to it. The information that the user provides when running the program is called "input", and the displayed response is called "output".


We use the input() function to read the user-provided data. It expects the user to enter a single line of text. After reading the data, the program executes the following instructions. Usually, the input data is stored in a variable. For example, the program:

text = input()
print(text + text)

will read one line and then print the entered text twice on the screen. The value obtained by the input() function is of string type. We can convert it to another type using type conversion. For example, the program:

number = int(input())
print(2 * number)

will read a string, convert it to a number, and then print a value twice as big.


Train with us!

example lesson on codeforia

Programming is a crucial aspect of learning to code. You can practice it by solving tasks (micro-projects) available on our educational platform Codeforia. Solutions are automatically checked, and shortly after submitting your code, you'll find out whether it's correct or needs modification. We also invite you to join our regular online classes, where you can further develop your skills under the guidance of an experienced trainer.

Check out our available courses.


Kursy programowania dla dzieci i młodzieży.

bottom of page