2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python - Check type of values

Posted at

Ref:
[1] - Stackoverflow - What's the canonical way to check for type in python?

Exact type

if type(o) is str:
  print "this is a string"

Instance of type or instance of the subclass

if isinstance(o, str):
  print "this is a string or a instance of subclass of string"

There are more patterns in the reference to deal with more complex usecases.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?