Python Forum
Is Python strongly or weakly typed? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Is Python strongly or weakly typed? (/thread-11476.html)



Is Python strongly or weakly typed? - amandio - Jul-10-2018

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?


RE: Is Python strongly or weakly typed? - snippsat - Jul-10-2018

(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


RE: Is Python strongly or weakly typed? - DeaD_EyE - Jul-12-2018

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'



RE: Is Python strongly or weakly typed? - amandio - Jul-13-2018

I asked the same question to Guido ... the answer follows in the image..
[Image: resposta1.jpg]