Junior — Middle
Is there strict type control over variables in Python?
sobes.tech AI
Answer from AI
Python lacks strict static typing like languages such as Java or C#. Variables are not bound to a specific type, and types are checked at runtime (dynamic typing). This means that a variable can be assigned a value of any type at any time.
However, starting with Python 3.5, type annotations (type hints) were introduced, allowing developers to specify expected types for variables and functions to improve readability and support static analysis tools, but they do not affect program execution.
Example of a type annotation:
def greet(name: str) -> str:
return 'Hello, ' + name
Thus, strict type control in Python is not enforced at the interpreter level but can be implemented using external tools (mypy, Pyright).