Home > Blockchain >  Is it possible to get an error when accidentally assigned wrong type in python?
Is it possible to get an error when accidentally assigned wrong type in python?

Time:07-30

For example I have next code:

name = str('John Doe')

Let's imagine after I assign to name = 1, but code still valid. Is it possible to get an error in this case in Python or within some special tool?

CodePudding user response:

Python is dynamically typed, so you can assign pretty much anything to anything. This would work:

name = 1
name = "Bill"

You can add in type checking with mypy

  • Related