Input and output¶
Content summary
This lesson explains how to read input and display output in Python.
Overview¶
In programming, input means the program receives data from the user, while output means the program displays information on the screen.
Reading input¶
Input in Python
To let the user enter data into a program, we use the built-in function input().
Example:
Lines 2 and 3 prompt the user to enter their username and password.
Running the code above produces the following result:
Displaying output¶
Output in Python
To display information on the screen, we use the print() function.
From now on, we will simply say: "print to the screen" or just "print".
Example:
Lines 5 and 6 print the username and password that the user just entered.
Running the code above produces the following result:
Tên đăng nhập: mrschool
Mật khẩu: 12345678
Tên đăng nhập của bạn là mrschool và mật khẩu là 12345678
Bạn đã bị hack 😆
f-string
f-string = formatted string.
An f-string lets you insert variables directly into a string using this syntax:
- Put the letter
fbefore the string:f'...' - Place the variable inside curly braces
{variable_name}
Using f-strings with print() is the modern, professional, and readable way in Python.
Source code¶
The complete code is available at:
Summary mindmap¶
Some English words¶
| Vietnamese | Tiếng Anh |
|---|---|
| dữ liệu đầu vào | input |
| thông tin đầu ra | output |

