Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 

>>> 
>>> S = 'Spam'
>>> len(S)
4
>>> S + 'Ni!'
'SpamNi!'
>>> 
>>> S * 8
'SpamSpamSpamSpamSpamSpamSpamSpam'
>>> 
>>> S[0]
'S'
>>> S[1]
'p'
>>> S[-1]
'm'
>>> S[-2]
'a'
>>> S[len(S)-1]
'm'
>>> S
'Spam'
>>> S[1:3]
'pa'
>>> S[1:]
'pam'
>>> S[:3]
'Spa'
>>> S[:-1]
'Spa'
>>> S[:]
'Spam'
>>> 
>>> S
'Spam'
>>> S.find('pa')
1
>>> S.replace('pa', 'XYZ')
'SXYZm'
>>> 
>>> S = 'aaa$bbb$ccc$ddd'
>>> S.reaplce('$', 'SPAM')

Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    S.reaplce('$', 'SPAM')
AttributeError: 'str' object has no attribute 'reaplce'
>>> 
>>> S.replece('$', 'SPAM')

Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    S.replece('$', 'SPAM')
AttributeError: 'str' object has no attribute 'replece'
>>> 
>>> 
>>> S.replace('$', 'SPAM')
'aaaSPAMbbbSPAMcccSPAMddd'
>>> 
>>> 
>>> line = 'aaa,bbb'ccc\n'
SyntaxError: invalid syntax
>>> 
>>> line = 'aaa,bbb,ccc\n'
>>> line[:-1]
'aaa,bbb,ccc'
>>> 
>>> line.rstrip()
'aaa,bbb,ccc'
>>> 
>>> line
'aaa,bbb,ccc\n'
>>> line.split(',')
['aaa', 'bbb', 'ccc\n']
>>> 
>>> line
'aaa,bbb,ccc\n'
>>> print line
aaa,bbb,ccc

>>> 
>>> dir(line)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> 
>>> line + 'lmnop'
'aaa,bbb,ccc\nlmnop'
>>> help(line.endswith)
Help on built-in function endswith:

endswith(...)
    S.endswith(suffix[, start[, end]]) -> bool
    
    Return True if S ends with the specified suffix, False otherwise.
    With optional start, test S beginning at that position.
    With optional end, stop comparing S at that position.
    suffix can also be a tuple of strings to try.

>>> help(line)
no Python documentation found for 'aaa,bbb,ccc'

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

class str(basestring)
 |  str(object) -> string
 |  
 |  Return a nice string representation of the object.
 |  If the argument is a string, the return value is the same object.
 |  
 |  Method resolution order:
 |      str
 |      basestring
 |      object
 |  
... 
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __new__ = <built-in method __new__ of type object>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T

>>>  help(line)
 
  File "<pyshell#53>", line 1
    help(line)
   ^
IndentationError: unexpected indent
>>> 
>>> rfind

Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    rfind
NameError: name 'rfind' is not defined
>>> help(str.rfind)
Help on method_descriptor:

rfind(...)
    S.rfind(sub [,start [,end]]) -> int
    
    Return the highest index in S where substring sub is found,
    such that sub is contained within s[start:end].  Optional
    arguments start and end are interpreted as in slice notation.
    
    Return -1 on failure.

>>> help(''.rfind)
Help on built-in function rfind:

rfind(...)
    S.rfind(sub [,start [,end]]) -> int
    
    Return the highest index in S where substring sub is found,
    such that sub is contained within s[start:end].  Optional
    arguments start and end are interpreted as in slice notation.
    
    Return -1 on failure.

>>> 
>>> 
>>> line
'aaa,bbb,ccc\n'
>>> 
>>> line.replace(',', '$$$')
'aaa$$$bbb$$$ccc\n'
>>> 
>>> line
'aaa,bbb,ccc\n'
>>> 
>>> line[0]
'a'
>>> line[0] = 'X'

Traceback (most recent call last):
  File "<pyshell#67>", line 1, in <module>
    line[0] = 'X'
TypeError: 'str' object does not support item assignment
>>> 
>>> line = line.replace(',', '$$$')
>>> line
'aaa$$$bbb$$$ccc\n'
>>> 
>>> 
>>> print 1, 2, 3
1 2 3
>>> print(1, 2, 3)
(1, 2, 3)
>>> print (1, 2, 3)
(1, 2, 3)
>>> 
>>> print 88
88
>>> print(99)
99
>>> print 'span', [1, 2, 3]
span [1, 2, 3]
>>> 
>>> print('span', [1, 2, 3])
('span', [1, 2, 3])
>>> 
>>> print 99, 24, (1, 2, 3), 66
99 24 (1, 2, 3) 66
>>> 
>>> import os
>>> os
<module 'os' from 'C:\Python27\lib\os.pyc'>
>>> 
>>> import a.b.c.d as d

Traceback (most recent call last):
  File "<pyshell#88>", line 1, in <module>
    import a.b.c.d as d
ImportError: No module named a.b.c.d
>>> 
>>> from a.b.c.d inport X  
KeyboardInterrupt
>>> 
>>> 

>>> 
>>> L = [123, 'spam', 1.23]
>>> len(L)
3
>>> L + [1, 2, 3]
[123, 'spam', 1.23, 1, 2, 3]
>>> L * 4
[123, 'spam', 1.23, 123, 'spam', 1.23, 123, 'spam', 1.23, 123, 'spam', 1.23]
>>> 
>>> L[0]
123
>>> L[-1]
1.23
>>> L[1:]
['spam', 1.23]
>>> 
>>> L.append(99)
>>> L
[123, 'spam', 1.23, 99]
>>> 
>>> L.remove(1.23)
>>> L
[123, 'spam', 99]
>>> L.insert(2, 'NI!')
>>> L
[123, 'spam', 'NI!', 99]
>>> L.pop(2)
'NI!'
>>> L
[123, 'spam', 99]
>>> 
>>> M = [[1, 2, 3],
         [4, 5, 6],
         [7, 8, 9]]
>>> M
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> M[1]
[4, 5, 6]
>>> M[1][2]
6
>>> [row[1] for row in M]
[2, 5, 8]
>>> 
>>> col2 = [row[1] for row in M]
>>> cols

Traceback (most recent call last):
  File "<pyshell#121>", line 1, in <module>
    cols
NameError: name 'cols' is not defined
>>> col2
[2, 5, 8]
>>> 
>>> [x ** 2 for x in [1, 2, 3, 5]]
[1, 4, 9, 25]
>>> 
>>> print 5
5
>>> print 2 ** 32
4294967296
>>> 
>>> a = 5
>>> 
>>> col = [row[1] for row in M]
>>> col
[2, 5, 8]
>>> 
>>> dir(M)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> 
>>> L = [1, 2, 3]
>>> 
>>> L[99]

Traceback (most recent call last):
  File "<pyshell#138>", line 1, in <module>
    L[99]
IndexError: list index out of range
>>> 
>>> L[0] = 'spam'
>>> L
['spam', 2, 3]
>>> 
>>> L[99] = 'ni'

Traceback (most recent call last):
  File "<pyshell#143>", line 1, in <module>
    L[99] = 'ni'
IndexError: list assignment index out of range
>>> 
>>> 
>>> D = {'food':'spam', 'taste':'yum'}

>>> D['food']
'spam'
>>> 
>>> D = {}
>>> D['name'] = 'Bob'
>>> D['job']   = 'dev'
>>> D['age']   = 45
>>> 
>>> D
{'age': 45, 'job': 'dev', 'name': 'Bob'}
>>> 
>>> D['name']
'Bob'
>>> 
>>> D = dict(name='Bob', job='dev', age=45)
>>> D
{'age': 45, 'job': 'dev', 'name': 'Bob'}
>>> 
>>> 
>>> rec = {'name': {'first': 'Bob', 'last': 'Smith'},
           'job':  ['dev', 'mgr'],
           'age':  45.6}
>>> rec['name']
{'last': 'Smith', 'first': 'Bob'}
>>> rec['name']['last']
'Smith'
>>> 
>>> rec['job']
['dev', 'mgr']
>>> rec['job'].append('janitor')
>>> rec
{'age': 45.6, 'job': ['dev', 'mgr', 'janitor'], 'name': {'last': 'Smith', 'first': 'Bob'}}
>>> 
>>> 
>>> zip([1, 2, 3], [8, 9, 0])
[(1, 8), (2, 9), (3, 0)]
>>> 
>>> help(list.sort)
Help on method_descriptor:

sort(...)
    L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
    cmp(x, y) -> -1, 0, 1

>>> rec = 0
>>> 
>>> 
>>> L = [1, 2, 3, 4, 5, 6]
>>> 
>>> M = [x * 2 for x in L]
>>> M
[2, 4, 6, 8, 10, 12]
>>> 
>>> N = map(lambda x: x * 2, L)
>>> N
[2, 4, 6, 8, 10, 12]
>>> 
>>> 
>>> b = lambda x: x * 2
>>> map(b, L)
[2, 4, 6, 8, 10, 12]
>>> 
>>> [abs(x) for x in L]
[1, 2, 3, 4, 5, 6]
>>> 
>>> map(abs, L)
[1, 2, 3, 4, 5, 6]
>>> 
>>> L = [(1, 2, 3), (0, 1, 2), (6, 7, 8)]
>>> L.sort(key=lambda x: x[1])
>>> L
[(0, 1, 2), (1, 2, 3), (6, 7, 8)]
>>> 
>>> 
>>> file = open('data.txt', 'w')
>>> file.write('Hello\n')
>>> file.write('world.\n')
>>> file.close()
>>> 
>>> file = open('data.txt')
>>> data = file.read()
>>> data
'Hello\nworld.\n'
>>> print data
Hello
world.

>>> 
>>> file = open('data.txt')
>>> file.readline()
'Hello\n'
>>> file.readline()
'world.\n'
>>> file.readline()
''
>>> 
>>> file = open('data.txt')
>>> file.read(10)
'Hello\nworl'
>>> file.read(10)
'd.\n'
>>> file.read(10)
''
>>> 
>>> file = open('data.txt', 'wb')
>>> import struct
>>> data = struct.pack('>i4sh', 5, 'spam', 6)
>>> data
'\x00\x00\x00\x05spam\x00\x06'
>>> file.write(data)
>>> file.close()
>>> 
>>> file = open('data.txt', 'rb')
>>> bytes = file.read()
>>> bytes
'\x00\x00\x00\x05spam\x00\x06'
>>> struct.unpack('>i4sh', bytes)
(5, 'spam', 6)
>>> 
>>> file = open('data.txt', 'rb')
>>> file2 = file  
KeyboardInterrupt
>>> 
>>> 
>>> 
>>> msg = '''
aaaaaaaaaaaaaaaaa
bbb"""bbbb''bbbbb
ccccccccccccc'''
>>> 
>>> msg
'\naaaaaaaaaaaaaaaaa\nbbb"""bbbb\'\'bbbbb\nccccccccccccc'
>>> print msg

aaaaaaaaaaaaaaaaa
bbb"""bbbb''bbbbb
ccccccccccccc
>>> 1, 2, 3
(1, 2, 3)
>>> 
>>> 
>>> X = None
>>> 
>>> L = []
>>> L[99] = 1

Traceback (most recent call last):
  File "<pyshell#249>", line 1, in <module>
    L[99] = 1
IndexError: list assignment index out of range
>>> 
>>> L = [None] * 100
>>> L
[None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]
>>> 
>>> type(L)
<type 'list'>
>>> 
>>> 
>>> X = {1, 2, 3, 4}
>>> 
>>> X
set([1, 2, 3, 4])
>>> 
>>> {a * 2 for s in X}
set([10])
>>> 
>>> {a * 2 for a in X}
set([8, 2, 4, 6])
>>> 
>>> 
>>> x
6
>>> X
set([1, 2, 3, 4])
>>> 
>>> X = {1, 2, 3, 4, 5}
>>> X & {3, 5, 7, 6}
set([3, 5])
>>> 
>>> X > {1, 2, 3}
True
>>> 
>>> X
set([1, 2, 3, 4, 5])
>>> X = {2, 3}
>>> 
>>> X = {1, 2, 3, 4, 5}
>>> X - {2, 3}
set([1, 4, 5])
>>> 
>>> L = [1, 2, 1, 3, 1, 4, 1]
>>> list(set(L))
[1, 2, 3, 4]
>>> 
>>> X = {1, 2, 3, 4}
>>> set([1, 2, 3, 4])
set([1, 2, 3, 4])
>>> 
>>> 
>>> 
>>> X = [1, 2, 3]
>>> Y = X
>>> 
>>> X == Y
True
>>> X is Y
True
>>> 
>>> X = [1, 2, 3]
>>> Y = [1, 2, 3]
>>> 
>>> X == Y
True
>>> X is Y
False
>>> 
>>> X = 88
>>> Y = 88
>>> 
>>> X == Y
True
>>> X is Y
True
>>> 
>>> ans = raw_input('Enter:')
Enter:spam
>>> ans
'spam'
>>> 
>>> 
>>> '42' + 1

Traceback (most recent call last):
  File "<pyshell#310>", line 1, in <module>
    '42' + 1
TypeError: cannot concatenate 'str' and 'int' objects
>>> 
>>> int('42')
42
>>> int('42') + 1
43
>>> 
>>> '42' + str(1)
'421'
>>> ================================ RESTART ================================
>>> 
Age=50
2500
Age=4
16
Age=stop
Bye
>>> ================================ RESTART ================================
>>> 
Age=spam

Traceback (most recent call last):
  File "C:/pyclass/interact.py", line 4, in <module>
    print int(inp) ** 2
ValueError: invalid literal for int() with base 10: 'spam'
>>> 
>>> s = '123'
>>> s.isdigit()
True
>>> ================================ RESTART ================================
>>> 
Age=7
49
Age=spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age=6
36
Age=stop
Bye
>>> ================================ RESTART ================================
>>> 
Age=20.5
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age=
>>> ================================ RESTART ================================
>>> 

Age=4
16.0
Age=2.5
6.25
Age=spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age=3
9.0
Age=stop
Bye
>>> ================================ RESTART ================================
>>> 
Age=8
64.0
Age=spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
<type 'exceptions.ValueError'>
Age=stop
Bye
>>> ================================ RESTART ================================
>>> 
Age=2 ** 4
256
Age=[2, 3, 4][0]
4
Age=stop
Bye
>>> import pdb
>>> pdb.run('import script1')
> <string>(1)<module>()
(Pdb) help

Documented commands (type help <topic>):
========================================
EOF    bt         cont      enable  jump  pp       run      unt   
a      c          continue  exit    l     q        s        until 
alias  cl         d         h       list  quit     step     up    
args   clear      debug     help    n     r        tbreak   w     
b      commands   disable   ignore  next  restart  u        whatis
break  condition  down      j       p     return   unalias  where 

Miscellaneous help topics:
==========================
exec  pdb

Undocumented commands:
======================
retval  rv

(Pdb) where
  c:\python27\lib\bdb.py(383)run()
-> exec cmd in globals, locals
> <string>(1)<module>()
(Pdb) quit
>>> 
>>> 
>>> (a, b) = [1, 2]
>>> a
1
>>> b
2
>>> (a, b) = [1, 2, 3]

Traceback (most recent call last):
  File "<pyshell#326>", line 1, in <module>
    (a, b) = [1, 2, 3]
ValueError: too many values to unpack
>>> 
>>> 
>>> 
>>> X = Y = 0
>>> X = X + 1
>>> X
1
>>> Y
0
>>> 
>>> X = Y = [0]
>>> X.append(1)
>>> X
[0, 1]
>>> Y
[0, 1]
>>> 
>>> X, Y = [], []
>>> X.append(0)
>>> X
[0]
>>> Y
[]
>>> X = X + 1

Traceback (most recent call last):
  File "<pyshell#344>", line 1, in <module>
    X = X + 1
TypeError: can only concatenate list (not "int") to list
>>> 
>>> 
>>> X = 0
>>> X = X + 1
>>> X += 1
>>> 
>>> L = [1, 2, 3]
>>> L.append(4)
>>> L
[1, 2, 3, 4]
>>> L = L.append(5)
>>> print L
None
>>> 
>>> import sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']
>>> help(sys.setrecursionlimit)
Help on built-in function setrecursionlimit in module sys:

setrecursionlimit(...)
    setrecursionlimit(n)
    
    Set the maximum depth of the Python interpreter stack to n.  This
    limit prevents infinite recursion from causing an overflow of the C
    stack and crashing Python.  The highest possible limit is platform-
    dependent.

>>> sys.getrecursionlimit()
1000
>>> def countdown(N):
	if N == 0:
		print 'stop'
	else:
		print N,
		countdown(N-1)

		
>>> countdown(20)
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 stop
>>> 
>>> 
>>> D = {'a': 1, 'b': 2, 'c': 3}
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> Ks = D.keys()
>>> Ks
['a', 'c', 'b']
>>> Ks.sort()
>>> Ks
['a', 'b', 'c']
>>> for key in Ks:
	print key, '=', D[key]

	
a = 1
b = 2
c = 3
>>> for c in 'spam':
	print c * 4

	
ssss
pppp
aaaa
mmmm
>>> 
>>> ord('s')
115
>>> ord('\n')
10
>>> ord('spam')

Traceback (most recent call last):
  File "<pyshell#388>", line 1, in <module>
    ord('spam')
TypeError: ord() expected a character, but string of length 4 found
>>> 
>>> S = 'spam'
>>> for c in S:
	print ord(c)

	
115
112
97
109
>>> 
>>> import docstrings
>>> print dosctrings.__doc__

Traceback (most recent call last):
  File "<pyshell#396>", line 1, in <module>
    print dosctrings.__doc__
NameError: name 'dosctrings' is not defined
>>> 
>>> print docstrings.__doc__

Module documentation
Words Go Here

>>> print docstrings.square.__doc__

    function documentation
    can we have your liver then?
    
>>> help(docstrings)
Help on module docstrings:

NAME
    docstrings

FILE
    c:\pyclass\docstrings.py

DESCRIPTION
    Module documentation
    Words Go Here

FUNCTIONS
    square(x)
        function documentation
        can we have your liver then?

DATA
    spam = 40


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

square(x)
    function documentation
    can we have your liver then?

>>> 
>>> file = open('script1.py')
>>> file.readline()
'# words go here\n'
>>> file.readline()
'print 2 ** 500\n'
>>> file.readline()
'import sys\n'
>>> file.readline()
'print sys.path         # import search path\n'
>>> file.readline()
"x = 'spam'\n"
>>> file.readline()
"print x + 'NI!'\n"
>>> file.readline()
'raw_input()\n'
>>> file.readline()
'\n'
>>> file.readline()
''
>>> file = open('script1.py')
>>> file.next()
'# words go here\n'
>>> file.next()
'print 2 ** 500\n'
>>> file.next()
'import sys\n'
>>> file.next()
'print sys.path         # import search path\n'
>>> file.next()
"x = 'spam'\n"
>>> file.next()
"print x + 'NI!'\n"
>>> file.next()
'raw_input()\n'
>>> file.next()
'\n'
>>> file.next()

Traceback (most recent call last):
  File "<pyshell#422>", line 1, in <module>
    file.next()
StopIteration
>>> 
>>> for line in open('script1.py'):
	print line.upper(),

	
# WORDS GO HERE
PRINT 2 ** 500
IMPORT SYS
PRINT SYS.PATH         # IMPORT SEARCH PATH
X = 'SPAM'
PRINT X + 'NI!'
RAW_INPUT()

>>> for line in open('script1.py').readlines():
	print line.upper(),

	
# WORDS GO HERE
PRINT 2 ** 500
IMPORT SYS
PRINT SYS.PATH         # IMPORT SEARCH PATH
X = 'SPAM'
PRINT X + 'NI!'
RAW_INPUT()

>>> file = open('script1.py')
>>> while True:
	line = file.readline()
	if not line: break
	print line.upper(),

	
# WORDS GO HERE
PRINT 2 ** 500
IMPORT SYS
PRINT SYS.PATH         # IMPORT SEARCH PATH
X = 'SPAM'
PRINT X + 'NI!'
RAW_INPUT()

>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> for key in D.keys():
	print key, D[key]

	
a 1
c 3
b 2
>>> for key in D:
	print key, D[key]

	
a 1
c 3
b 2
>>> 
>>> 
>>> 
>>> S[I:J:K] 
KeyboardInterrupt
>>> 
>>> 
>>> S = 'abcdefghijklmnop'
>>> S[::2]
'acegikmo'
>>> S[1::2]
'bdfhjlnp'
>>> S[1:100:2]
'bdfhjlnp'
>>> 
>>> S[::-1]
'ponmlkjihgfedcba'
>>> 
>>> 
>>> L = [1, 2, 3, 4, 5]
>>> for x in L:
	x += 10

	
>>> x
15
>>> L
[1, 2, 3, 4, 5]
>>> 
>>> for i in range(len(L)):
	L[i] += 10

	
>>> L
[11, 12, 13, 14, 15]
>>> 
>>> M = [x + 10 for x in L]
>>> M
[21, 22, 23, 24, 25]
>>> 
>>> res = []
>>> for x in L:
	res.append(x + 10)

	
>>> res
[21, 22, 23, 24, 25]
>>> 
>>> res = []
>>> for c in 'spam':
	res.append(ord(c))

	
>>> res
[115, 112, 97, 109]
>>> 
>>> res = [ord(c) for c in 'spam']
>>> res
[115, 112, 97, 109]
>>> 
>>> map(ord, 'spam')
[115, 112, 97, 109]
>>> 
>>> file = open('script1.py')
>>> lines.readlines()

Traceback (most recent call last):
  File "<pyshell#488>", line 1, in <module>
    lines.readlines()
NameError: name 'lines' is not defined
>>> 
>>> lines = file.readlines()
>>> lines
['# words go here\n', 'print 2 ** 500\n', 'import sys\n', 'print sys.path         # import search path\n', "x = 'spam'\n", "print x + 'NI!'\n", 'raw_input()\n', '\n']
>>> 
>>> lines = [line.rstrip() for line in lines]
>>> loines

Traceback (most recent call last):
  File "<pyshell#494>", line 1, in <module>
    loines
NameError: name 'loines' is not defined
>>> lines
['# words go here', 'print 2 ** 500', 'import sys', 'print sys.path         # import search path', "x = 'spam'", "print x + 'NI!'", 'raw_input()', '']
>>> 
>>> lines = [line.rstrip() for line in open('script1.py')]
>>> lines
['# words go here', 'print 2 ** 500', 'import sys', 'print sys.path         # import search path', "x = 'spam'", "print x + 'NI!'", 'raw_input()', '']
>>> lines = [line.rstrip() for line in open('script1.py') if line[0] == 'p']
>>> lines
['print 2 ** 500', 'print sys.path         # import search path', "print x + 'NI!'"]
>>> 
>>> [x + y for x in 'abc' for y in 'lmn']
['al', 'am', 'an', 'bl', 'bm', 'bn', 'cl', 'cm', 'cn']
>>> 
>>> res = []
>>> for x in 'abc':
	for y in 'lmn':
		res.append(x + y)

		
>>> res
['al', 'am', 'an', 'bl', 'bm', 'bn', 'cl', 'cm', 'cn']
>>> 
>>> res = []
>>> for line in open('script1.py'):
	if line[0] == 'p':
		res.append(line.rstrip())

		
>>> res
['print 2 ** 500', 'print sys.path         # import search path', "print x + 'NI!'"]
>>> 
>>> import __builtin__
>>> dir(__builtin__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>> 
>>> 
>>> True = False
>>> True
False
>>> __builtin__.True = False  
KeyboardInterrupt
>>> 
>>> 
>>> 
>>> def maker(N):
	def action(X):
		return X ** N
	return action

>>> F = maker(2)
>>> F
<function action at 0x0000000003BFFC88>
>>> F(3)
9
>>> F(4)
16
>>> G = maker(3)
>>> G(3)
27
>>> G(4)
64
>>> 
>>> F(3)
9
>>> X = 99
>>> type(X)
<type 'int'>
>>> 
>>> type('spam')
<type 'str'>
>>> 
>>> def mysum(*args):
	tot = 0
	for x in args:
		tot += x
	return tot

>>> mysum(1, 2, 3, 4)
10
>>> 
>>> def mysum(*args):
	tot = args[0]
	for x in args[1:]
	
SyntaxError: invalid syntax
>>> 
>>> def adder(A=1, B=2, C=3): return A + B + C

>>> adder(C=99)
102
>>> 
>>> 
>>> acts = [lambda X: X ** 2,
	    lambda X: X ** 3,
	    lambda X: X ** 4]
>>> acts
[<function <lambda> at 0x0000000003BFFEB8>, <function <lambda> at 0x0000000003BFFDD8>, <function <lambda> at 0x0000000003BFFF28>]
>>> 
>>> for i in range(3):
	print i, acts[i]()

	
0

Traceback (most recent call last):
  File "<pyshell#568>", line 2, in <module>
    print i, acts[i]()
TypeError: <lambda>() takes exactly 1 argument (0 given)
>>> 
>>> 
>>> for i in range(3):
	print i, acts[i](2)

	
0 4
1 8
2 16
>>> def f1(X): return X ** 2

>>> def f2(X): return X ** 3

>>> acts2 = [f1, f2]
>>> acts2
[<function f1 at 0x0000000003BFFF98>, <function f2 at 0x0000000003C00048>]
>>> for i in range(3):
	print i, acts2[i](2)

	
0 4
1 8
2

Traceback (most recent call last):
  File "<pyshell#580>", line 2, in <module>
    print i, acts2[i](2)
IndexError: list index out of range
>>> 
>>> 
>>> [x ** 2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> 
>>> G = (x ** 2 for x in range(10))
>>> G
<generator object <genexpr> at 0x0000000003946750>
>>> list(G)
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> 
>>> {x ** 2 for x in range(10)}
set([0, 1, 4, 81, 64, 9, 16, 49, 25, 36])
>>> 
>>> {x : x ** 2 for x in range(10)}
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
>>> ================================ RESTART ================================
>>> 
10

Traceback (most recent call last):
  File "C:/pyclass/mysum.py", line 9, in <module>
    print mysun('aa', 'bb', 'cc')
NameError: name 'mysun' is not defined
>>> ================================ RESTART ================================
>>> 
10
aabbcc
>>> ================================ RESTART ================================
>>> 
I am: __main__
10
aabbcc
>>> import mysum
I am: mysum
>>> mysum.mysum(1, 2, 3, 4, 5)
15
>>> 
>>> 
>>> fname = 'script1.py'
>>> len(open(fname).readlines())
8
>>> len(open(fname).read())
126
>>> 
>>> tot = 0
>>> for line in open(fname): tot += 1

>>> tot
8
>>> tot = 0
>>> for line in open(fname): tot += len(line)

>>> tot
126
>>> 
>>> def countLines(fname:
	       
SyntaxError: invalid syntax
>>> def countLines(fname):
	return len(open(fname).readlines())

>>> 
