Python Forum

Full Version: Is Python strongly or weakly typed?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm a computers network studant from João Pessoa-Paraiba-Brazil, and I'm studying programming. Python is the programming language that we are atudying and in one of the exams that I made, there was a question saying "Python is strongly typed".

The teacher said this answer was wrong because Python is weakly typed. I believed the teacher, but I'm engaged in my studies, so after some time I decided to search about this and after a lot of search and interaction on forums about Python, I'm almost sure that this is a strongly typed language.

Is Python strongly or weakly typed?
(Jul-10-2018, 05:31 PM)amandio Wrote: [ -> ]Is Python strongly or weakly typed?
Python is strongly typed.
>>> a = 5
>>> b = '6'
>>> a + b
Traceback (most recent call last):
  File "<string>", line 428, in runcode
  File "<interactive input>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
To read more about it:
Why is Python a dynamic language and also a strongly typed language
Let's make a collection of TypeError, ValueError, InvalidOperation, etc.

In [68]: int('0.3')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-68-0d64588ae80e> in <module>()
----> 1 int('0.3')

ValueError: invalid literal for int() with base 10: '0.3'
I asked the same question to Guido ... the answer follows in the image..
[Image: resposta1.jpg]