Python: Strongly Typed
When observing Python code it may appear to be loosely typed. If a person considers variable declaration, they may consider Python as loosely typed because a variable can be reassigned to a different type.
length = 30 length = "30"
The above is valid in Python, as the variable has been reassigned from an integer to a string.
However, Python will not allow casting of an int into a string, nor will it allow the passing of invalid types of numbers:
Code language: PHP (php)
# below will fail as the integer can't be cast into the string as is: print("My name is Jason and I am " + 8 + " years old") # below will fail because a float can not be used in this integer operation: for i in range(1, 4.5): print(i)
While Python is not as strongly typed as Java or C, it does have restrictions on variable types (as seen above.)