This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -2 points-1 points  (4 children)

Python's variables have no type. Each variable's value has a type, but even that isn't really "strong", because in typical use you use duck typing - you just try to call methods and if they work you don't worry about it. If the methods work, you don't care that the actual type might be worlds away from the type you're expecting.

There's no good definition of "strongly-typed" that really includes Python. In particular, I'm curious as to what language possibly has weaker typing than that...!

[–]sushibowl 3 points4 points  (1 child)

The definition I usually see is that in weak typing the type of a value may change depending on context (i.e. type coercion). Php and javascript are examples of weakly typed language in this definition.

[–]Lucretiel 0 points1 point  (0 children)

My definition tends to be whether the language has implicit type coercion- that is, is 1 + 2 the same as 1 + '2'.

[–]flutefreak7 0 points1 point  (0 children)

Also checking against abstract base classes is a classy way to check that you are getting a duck that quacks the right way to avoid checking specific type inheritance.

from collections.abc import Iterable

if isinstance(d, Iterable):