
Python Basics
Variables & constants, data types, control flow, functions, list comprehensions, decorators, context managers
1What is the difference between a variable declared with = and a constant in Python?
What is the difference between a variable declared with = and a constant in Python?
답변
Python does not have true constants at the language level. By convention, UPPERCASE variables are considered constants and should not be modified, but nothing technically prevents reassignment. This PEP 8 convention relies on developer discipline rather than language enforcement.
2What data type does the expression 3 / 2 return in Python 3?
What data type does the expression 3 / 2 return in Python 3?
답변
In Python 3, the / operator always performs floating-point division, returning 1.5 in this case. To get integer division, use the // operator. This is a major difference from Python 2 where / performed integer division between two integers.
3What is the difference between a list and a tuple in Python?
What is the difference between a list and a tuple in Python?
답변
Lists are mutable (modifiable after creation) while tuples are immutable. Tuples are slightly more performant and can be used as dictionary keys. Lists use square brackets [] and tuples use parentheses (). Choose the right type based on whether data needs to be modified.
How to check if a key exists in a Python dictionary?
What is the difference between == and is in Python?
+22 면접 질문