Python - 4
Python - 4
3. How does the elif statement work in Python? Can we use it multiple
times?
Answer: The elif (else if) statement in Python is used for multiple
condition checks. It follows an if statement and is checked only if the
previous condition is False. If an elif condition is True, its block
executes, and the rest are skipped
Yes we can use it multiple times
5. How can we iterate over a range in reverse order using range()?
Answer:You can iterate over a range in reverse order using range()
with a negative step.
For example
for i in range(10, 0, -1):
print(i)
7. What is the difference between local and global variables in Python?
Answer:Local Variable: A variable declared inside a function and
accessible only within that function
Global Variable: A variable declared outside any function and
accessible throughout the program, including inside functions