Q1. How do you take user input in Python?
Use the input() function. It returns a string. Example:
name = input("Enter your name: ") To convert to integer, use int(input()).Q2. How do you print output in Python?
Use the print() function. It can accept multiple arguments, separated by commas. You can control separators and end-of-line. Example:
print("Hello", "World", sep="-", end="!")Q3. What is formatted output (f-strings) in Python?
f-strings allow embedding expressions inside string literals using curly braces. Example:
name = "Alice"
print(f"Hello {name}") They are efficient and readable.Q4. What is the difference between print() and sys.stdout.write()?
print() is a high-level function that automatically adds a newline and converts arguments to strings. sys.stdout.write() writes raw bytes without newline and requires manual conversion. print() is more convenient for general use.
Q5. How do you read multiple values from user input?
Use input().split() to split a line into multiple values. Example:
a, b = input("Enter two numbers: ").split() Convert each as needed, e.g., int(a).