>>> import sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__stdin__', '__stdout__', '_getframe', 'argv', 'builtin_module_names', 'byteorder', 'copyright', 'displayhook', 'dllhandle', 'exc_info', 'exc_type', 'excepthook', ...pozostałe pominięto...]


>>> dir([])
['__add__', '__class__', ...więcej... 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

>>> dir('')
['__add__', '__class__', ...więcej... 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', ...pozostałe pominięto...]


>>> dir(str) == dir('')                      # Ten sam wynik co w poprzednim przykładzie
True
>>> dir(list) == dir([])
True


# Plik docstrings.py

# -*- coding: utf-8 -*-
"""
Dokumentacja modułu
Tutaj jego opis
"""

spam = 40

def square(x):
   """
   Dokumentacja funkcji
   Możemy wziąć Pańską wątrobę?
   """
   return x **2

class employee:
   "dokumentacja klasy"
   pass

print square(4)
print square.__doc__


>>> import docstrings
16

   Dokumentacja funkcji
   Możemy wziąć Pańską wątrobę?

>>> print docstrings.__doc__

Dokumentacja modułu
Tutaj jego opis

>>> print docstrings.square.__doc__
   
   Dokumentacja funkcji
   Możemy wziąć Pańską wątrobę?

>>> print docstrings.employee.__doc__
   dokumentacja klasy


>>> import sys
>>> print sys.__doc__
This module provides access to some objects used or maintained by the interpreter and to
...resztę tekstu pominięto...

Dynamic objects:

argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules
...resztę tekstu pominięto...


>>> print sys.getrefcount.__doc__
getrefcount(object) -> integer

Return the current reference count for the object.
...resztę tekstu pominięto...


>>> print int.__doc__
int(x[, base]) -> integer

Convert a string or number to an integer, if possible.
...resztę tekstu pominięto...

>>> print open.__doc__
file(name[, mode[, buffering]]) -> file object

Open a file. The mode can be 'r', 'w' or 'a' for reading
...resztę tekstu pominięto...


>>> import sys
>>> help(sys.getrefcount)
Help on built-in function getrefcount:

getrefcount(...)
   getrefcount(object) -> integer

   Return the current reference count for the object.
   ...resztę tekstu pominięto...


>>> help(sys)
Help on built-in module sys:

NAME
   sys

FILE
   (built-in)

MODULE DOCS
    http://www.python.org/doc/current/lib/module-sys.html

DESCRIPTION
   This module provides access to some objects used or maintained by the interpreter and to functions
   ...resztę tekstu pominięto...

FUNCTIONS
   __displayhook__ = displayhook(...)
      displayhook(object) -> None
      
      Print an object to sys.stdout and also save it
   ...resztę tekstu pominięto...

DATA
   __name__ = 'sys'
   __stderr__ = <open file '<stderr>', mode 'w' at 0x0082BEC0>
   ...resztę tekstu pominięto...

   
>>> help(dict)
Help on class dict in module __builtin__:

class dict(object)
 | dict( ) -> new empty dictionary.
 ...resztę tekstu pominięto...

>>> help(str.replace)
Help on method_descriptor:

replace(...)
   S.replace (old, new[, maxsplit]) -> string
   Return a copy of string S with all occurrences
   ...resztę tekstu pominięto...

>>> help(ord)
Help on built-in function ord:

ord(...)
   ord(c) -> integer

   Return the integer ordinal of a one-character string.

   
>>> help(docstrings.square)
Help on function square in module docstrings:

square(x)
   Dokumentacja funkcji
   Możemy wziąć Pańską wątrobę?

>>> help(docstrings.employee)
Help on class employee in module docstrings:

class employee
 |  dokumentacja klasy

>>> help(docstrings)
Help on module docstrings:

NAME
   docstrings

FILE
   c:\python22\docstrings.py

DESCRIPTION
   Dokumentacja modułu
   Tutaj jego opis

CLASSES
   employee
   ...resztę tekstu pominięto...

FUNCTIONS
   square(x)
      Dokumentacja funkcji
      Możemy wziąć Pańską wątrobę?

DATA
   __file__ = 'C:\\PYTHON22\\docstrings.pyc'
   __name__ = 'docstrings'
   spam = 40   

   
for i in range(50):
   print 'Witaj %d\n\a' % i


# Plik power.py

L = [1, 2, 4, 8, 16, 32, 64]
X = 5

found = i = 0
while not found and i < len(L):
   if 2 ** X == L[i]:
      found = 1
   else:
      i = i+1   
if found:
   print 'pod indeksem', i
else:
   print X, 'nie odnaleziono'


C:\book\tests> python power.py
pod indeksem 5