Common Python Errors and Programming Concepts Flashcards
(31 cards)
What is a syntax error?
A mistake in the structure of the code (e.g., missing colon or parentheses).
What is a runtime error?
An error that occurs while the program is running (e.g., division by zero).
What is a logical error?
A mistake in the program’s logic that causes incorrect results but no crash.
How do you convert a string to an integer?
Use int(“5”).
What is the order of operations in Python?
Parentheses, Exponents, Multiplication/Division, Addition/Subtraction (PEMDAS).
Are strings mutable?
No, they are immutable.
Are lists mutable?
Yes, you can change, add, or remove elements.
How do you slice a list or string?
Use [start:end], where end is not included.
What are some string methods?
.lower(), .find()
What are some list methods?
.append(), .sort()
What does the and operator do?
Returns True only if both conditions are True.
What does the or operator do?
Returns True if at least one condition is True.
What does the not operator do?
Reverses the Boolean value.
What is the output of range(5)?
0, 1, 2, 3, 4
What is an infinite loop?
A loop that never ends due to a missing exit condition.
How do you iterate over a list element-wise?
for item in my_list:
How do you iterate index-wise?
for i in range(len(my_list)):
Why use functions?
To reuse code, reduce repetition, and improve readability.
What is variable scope?
Where a variable can be accessed (local vs. global).
What happens if a function returns without a return statement?
None
How do you access a value by key in a dictionary?
dict[key]
How do you loop through dictionary items?
for key, value in dict.items():
What are some dictionary methods?
.get(), .update()
How do you open a file for reading?
open(“file.txt”, “r”)