Module 2: Python Basics - Data Types, Variables, I/O, and Operators
Basic Input and Output (I/O)
-
Output (
print()
): We've seenprint()
for displaying information.print("Name:", name, "Age:", age)
-
Input (
input()
): Used to get data from the user. It always returns the input as a string.user_name = input("Enter your name: ")
If you need a number, you must convert it:user_age_str = input("Enter your age: "); user_age_int = int(user_age_str)
Note for Sandbox: In this online sandbox,
input()
doesn't work like a normal terminal. For labs, we'll simulate input by setting variables directly in the code.