Python Datatypes Overview

Common Python datatypes include:

Detection

Use the type() function to detect the datatype of any object:

type("Hello") #> <type 'str'>
type("100") #> <type 'str'>
type(100) #> <type 'int'>
type(0.45) #> <type 'float'>
type(True) #> <type 'bool'>
type(False) #> <type 'bool'>
type(None) #> <type 'NoneType'>
type({"a":1, "b":2, "c":3}) #> <type 'dict'>
type([1,2,3]) #> <type 'list'>

Alternatively call .__class__.__name__ on any object to detect its class name:

Use the isinstance function when comparing datatypes:

Conversion

Here are a few examples of how to convert between datatypes:

Last updated

Was this helpful?