Input and Output
Every program interacts with the user through input and output. Python provides simple functions: `print()` for output and `input()` for reading user input.
Print Function
The `print()` function outputs text to the console. You can print multiple items separated by commas, and they will be joined with spaces by default.
print("Hello", "World!") # Hello World!
print(42, "is the answer")
Input Function
`input()` reads a line from the user and returns it as a string. You can display a prompt by passing a string argument.
name = input("Enter your name: ")
print("Hello, " + name)
Formatting Output
You can format strings in several ways. The most modern is using f-strings (formatted string literals).
age = 25
print(f"I am {age} years old.") # I am 25 years old.
# You can also use .format()
print("I am {} years old.".format(age))
Two Minute Drill
- `print()` outputs text to the console; can take multiple arguments.
- `input()` reads user input as a string.
- Use f-strings for easy formatting: `f"Hello {name}"`.
- Concatenate strings with `+` but be careful with types.
Need more clarification?
Drop us an email at career@quipoinfotech.com
