Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Literals, Value Types in Python

  • int
  • str
  • float
  • bool
print( type(23) )        # int
print( type(3.14) )      # float
print( type("hello") )   # str

print( type("23") )      # str
print( type("3.24") )    # str

print( type(None) )      # NoneType
print( type(True) )      # bool
print( type(False) )     # bool

print( type([]) )        # list
print( type({}) )        # dict

print( type(hello) )     #  NameError: name 'hello' is not defined
print("Still running")

Output:

Traceback (most recent call last):
  File "python/examples/basics/types.py", line 15, in <module>
    print( type(hello) )   # str
NameError: name 'hello' is not defined
  • Strings must be enclosed in quotes.
  • Numbers must be NOT enclosed in quotes.