-
How do you create a variable in Python?
Assign a value to a variable name with the = symbol, like: x = 10.
-
What symbol is used for comments in Python?
The # symbol is used for single-line comments.
-
What is a string in Python?
A sequence of characters enclosed in quotes, like "Hello" or 'Python'.
-
How do you get user input in Python?
Use the input() function, like: name = input("Enter your name: ").
-
What are the basic data types in Python?
Common types include integers (int), floating-point numbers (float), strings (str), and booleans (bool).
-
How do you create a list in Python?
Use square brackets: my_list = [1, 2, 3].
-
How do you access the first element of a list?
Use indexing: my_list[0].
-
What is a function in Python?
A block of reusable code that performs a specific task. Defined using the def keyword.
-
How do you define a function in Python?
Use def, the function name, and parentheses: def my_function():.
-
What does if do in Python?
if checks a condition and executes code if the condition is true.
-
How do you check if x is greater than 10 in Python?
Use an if statement: if x > 10:.
-
What is a loop in Python?
A way to repeat a block of code multiple times. Common loops are for and while.
-
How do you create a for loop that prints numbers 1 to 5?
Use the range function: for i in range(1, 6): print(i).
-
How do you create a while loop in Python?
Use while and a condition: while x < 5: print(x); x += 1.
-
What does len() do in Python?
It returns the length of an object, like a list or string.
-
How do you import a module in Python?
Use the import keyword: import math.
-
What is the purpose of return in a function?
It sends a value back from a function to the caller.
-
How do you handle errors in Python?
Use try and except blocks to catch and handle exceptions.
|
|