What function is used to display output in Python?
print()
What is a variable in Python?
A named location in memory used to store data.
Which function is used to get user input in Python?
input()
What is the symbol for addition in Python?
+
How do you concatenate two strings in Python?
Use +.
How do you print multiple items in one line?
Use commas or sep parameter in print().
List three different data types in Python.
Integer, Float, String.
How do you ensure that the input received is treated as an integer?
Wrap input in int(): age = int(input("Enter your age: ")).
How do you denote exponentiation in Python?
Use **.
What method would you use to find the length of a string?
Use len(string).
How can you format strings when printing, using placeholders?
Use formatted strings or f-strings: print(f"My name is {name}").
How do you convert a string to an integer in Python?
int(variable_name).
Write a line of code that prompts the user for their name and stores it in a variable.
name = input("What is your name? ").
What is the output of the expression 7 % 3?
1 (remainder of 7 divided by 3).
How can you convert a string to all uppercase letters?
Use upper(): string.upper().
What is the purpose of the end parameter in the print() function?
It changes the string printed at the end of the output; default is a new line.
What is the difference between a list and a tuple in Python?
Lists are mutable; tuples are immutable.
What happens if you try to convert a non-numeric string to an integer using int()?
It will raise a ValueError.
How can you use the // operator, and what does it do?
It performs floor division, returning the largest integer less than or equal to the division.
What is the result of "hello".replace("l", "x")?
"hexo".
Explain how to print a string that includes both single and double quotes.
Use escape characters: print("He said, \"Hello!\"").
Explain what dynamic typing means in Python.
Variables can change types without explicit declaration.
Explain how to handle exceptions when user input is not as expected.
Use try-except blocks to handle exceptions.
Explain the difference between = and == in Python.
= is assignment, == is comparison.
Explain how string slicing works with an example.
string[start:end].