Standard LibraryΒΆ

  • Python contains hundreds of standard library modules performing a variety of common tasks.
  • Use standard functions over custom code when possible for clarity, portability and (usually) speed.
  • Common standard modules include math, random, time, os and sys. Import them
  • Even standard modules must be imported before use.
  • Some very common functions (e.g., file I/O) are built-in functions (no import needed).
>>> import math
>>> math.sqrt(2.0)
>>> f = open("file.txt", "r")
>>> type(f)
<type 'file'>
>>> lines = f.readlines()    # Reads file into list of strings.
>>> ...