Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
    
IDLE 1.2      
>>> 
>>> 2 ** 80
1208925819614629174706176L
>>> 
>>> 'spam' + 'NI'
'spamNI'
>>> 
>>> import sys
>>> sys.platform
'win32'
>>> 
>>> ================================ RESTART ================================
>>> 
1809251394333065553493296640760748560207343510400633813116524750123642650624
win32
SpamNI!
>>> 
>>> S = 'spam'
>>> 
>>> len(S)
4
>>> S + 'NI'
'spamNI'
>>> 
>>> S * 8
'spamspamspamspamspamspamspamspam'
>>> 
>>> S[0]
's'
>>> S[1]
'p'
>>> 
>>> S[99]

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    S[99]
IndexError: string index out of range
>>> 
>>> S[-1]
'm'
>>> S[-2]
'a'
>>> 
>>> S[len(S)-1]
'm'
>>> S[-1]
'm'
>>> S
'spam'
>>> 
>>> X[I:J]  
KeyboardInterrupt
>>> 
>>> 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
'spam'
>>> 
>>> S = S.replace('pa', 'XYZ')
>>> S
'sXYZm'
>>> 
>>> S = 'spam'
>>> S = 'lmnop'
>>> 
>>> S
'lmnop'
>>> S[0]
'l'
>>> S[0] = 'x'

Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    S[0] = 'x'
TypeError: 'str' object does not support item assignment
>>> 
>>> line = 'aaaaaa\n'
>>> likne[:-1]

Traceback (most recent call last):
  File "<pyshell#58>", line 1, in <module>
    likne[:-1]
NameError: name 'likne' is not defined
>>> 
>>> line[-1]
'\n'
>>> 
>>> 
>>> line
'aaaaaa\n'
>>> line[:-1]
'aaaaaa'
>>> 
>>> line
'aaaaaa\n'
>>> line.rstrip()
'aaaaaa'
>>> 
>>> line = 'aaa,bbb,ccc'
>>> 
>>> cols = line.split(',')
>>> cols
['aaa', 'bbb', 'ccc']
>>> 
>>> line
'aaa,bbb,ccc'
>>> dir(line)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', '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']
>>> 
>>> 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.

>>> import sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', '__stdin__', '__stdout__', '_current_frames', '_getframe', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'exc_clear', 'exc_info', 'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getrecursionlimit', 'getrefcount', 'getwindowsversion', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'maxint', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']
>>> help(sys.getrefcount)
Help on built-in function getrefcount in module sys:

getrefcount(...)
    getrefcount(object) -> integer
    
    Return the reference count of object.  The count returned is generally
    one higher than you might expect, because it includes the (temporary)
    reference as an argument to getrefcount().

>>> 
>>> L = [123, 'spam', 1.23]
>>> 
>>> len(L)
3
>>> L + [5, 6, 7]
[123, 'spam', 1.23, 5, 6, 7]
>>> 
>>> L * 5
[123, 'spam', 1.23, 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
[123, 'spam', 1.23]
>>> 
>>> L.append('NI')
>>> L
[123, 'spam', 1.23, 'NI']
>>> 
>>> L.remove(1.23)
>>> L
[123, 'spam', 'NI']
>>> 
>>> L
[123, 'spam', 'NI']
>>> L.append([5, 6, 7])
>>> L
[123, 'spam', 'NI', [5, 6, 7]]
>>> 
>>> L = [123, 'spam']
>>> L.extend([5, 6, 7])
>>> L
[123, 'spam', 5, 6, 7]
>>> L[0] = 'xyz'
>>> L
['xyz', 'spam', 5, 6, 7]
>>> 
>>> 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
>>> 
>>> col2 = [row[1] for row in M]
>>> col2
[2, 5, 8]
>>> 
>>> D = {}
>>> D['name'] = 'Bob'
>>> D['job']  = 'dev'
>>> D['age']  = 40
>>> 
>>> D
{'age': 40, 'job': 'dev', 'name': 'Bob'}
>>> 
>>> print D['name']
Bob
>>> 
>>> rec = {'name': {'first': 'Bob', 'last': 'Smith'},
           'job':  ['dev', 'mgr'],
           'age':  40.5}
>>> 
>>> rec['name']
{'last': 'Smith', 'first': 'Bob'}
>>> rec['name']['last']
'Smith'
>>> 
>>> rec['job'][-1]
'mgr'
>>> rec['job'].append('janitor')
>>> rec
{'age': 40.5, 'job': ['dev', 'mgr', 'janitor'], 'name': {'last': 'Smith', 'first': 'Bob'}}
>>> 
>>> rec = 0
>>> rec = {'name': {'first': 'Bob', 'last': 'Smith'},
           'job':  ['dev', 'mgr'],
           'age':  40.5}
>>> rec['job'].append('janitor')
>>> 
>>> rec
{'age': 40.5, 'job': ['dev', 'mgr', 'janitor'], 'name': {'last': 'Smith', 'first': 'Bob'}}
>>> 
>>> rec['job']
['dev', 'mgr', 'janitor']
>>> rec['job'].remove('janitor')
KeyboardInterrupt
>>> 
>>> del
SyntaxError: invalid syntax
>>> 
>>> del rec['job'][2]
>>> rec
{'age': 40.5, 'job': ['dev', 'mgr'], 'name': {'last': 'Smith', 'first': 'Bob'}}
>>> 

>>> 
>>> int('FFFF", 16)
    
SyntaxError: EOL while scanning single-quoted string
>>> 
>>> 
>>> int('FFFF', 16)
65535
>>> 
>>> 
>>> I = 16
>>> 
>>> hex(I)
'0x10'
>>> S = hex(I)
>>> S
'0x10'
>>> 
>>> int(S, 16)
16
>>> 
>>> S
'0x10'
>>> 
>>> eval(S)
16
>>> 
>>> 123 + 1.23
124.23
>>> 
>>> 
>>> S = '42'
>>> I = 1
>>> 
>>> S + I

Traceback (most recent call last):
  File "<pyshell#181>", line 1, in <module>
    S + I
TypeError: cannot concatenate 'str' and 'int' objects
>>> 
>>> int(S)
42
>>> int(S) + I
43
>>> 
>>> str(I)
'1'
>>> S + str(I)
'421'
>>> X = 4 / 5.0
>>> 
>>> X
0.80000000000000004
>>> 
>>> round(X, 2)
0.80000000000000004
>>> 
>>> 
>>> Y = 1 / 2.0
>>> Y
0.5
>>> Z = 1 / 3.0
>>> Z
0.33333333333333331
>>> round(Z, 2)
0.33000000000000002
>>> 
>>> 
>>> 
>>> X = 99
>>> X = 'spam'
>>> X = 1.23
>>> 
>>> 
>>> X = [1, 2, 3]
>>> Y = X
>>> 
>>> X[0] = 4
>>> X
[4, 2, 3]
>>> Y
[4, 2, 3]
>>> 
>>> X
[4, 2, 3]
>>> 
>>> X[0] = 'spam'
>>> X[1] = 1.23
>>> X
['spam', 1.23, 3]
>>> 
>>> X = [1, 2, 3]
>>> Y = X[:]
>>> X[0] = 4
>>> X
[4, 2, 3]
>>> Y
[1, 2, 3]
>>> 
>>> 
>>> X = [1, 2, 3]
>>> Y = X
>>> 
>>> X == Y
True
>>> 
>>> X is Y
True
>>> 
>>> X = [1, 2, 3]
>>> Y = X[:]
>>> X == Y
True
>>> X is Y
False
>>> 
>>> S = 'A\nB\tC'
>>> 
>>> len(S)
5
>>> ord('\n')
10
>>> chr(10)
'\n'
>>> S = 'A\0B\0C'
>>> 
>>> len(S)
5
>>> 
>>> msg = """
aaaaaaaaaaaaaaaaaaa
bbbbbb'''''bbbb""bbbbbbbbb
cccccccccccccccc"""
>>> 
>>> msg
'\naaaaaaaaaaaaaaaaaaa\nbbbbbb\'\'\'\'\'bbbb""bbbbbbbbb\ncccccccccccccccc'
>>> print

>>> print msg

aaaaaaaaaaaaaaaaaaa
bbbbbb'''''bbbb""bbbbbbbbb
cccccccccccccccc
>>> 
>>> 
>>> open(r'C:\new\text') 
KeyboardInterrupt
>>> 
>>> 
>>> u'xxxxx'
KeyboardInterrupt
>>> 
>>> D = {'a':1, 'b': 2}
>>> 
>>> D['c'] = 3
>>> D['d']

Traceback (most recent call last):
  File "<pyshell#265>", line 1, in <module>
    D['d']
KeyError: 'd'
>>> 
>>> D.has_key('c')
True
>>> D.has_key('d')
False
>>> 
>>> if not D.has_key('e'):
	print 'missing'

	
missing
>>> 
>>> if not 'e' in D:
	print 'missing'

	
missing
>>> 
>>> 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.upper()

	
S
P
A
M
>>> 
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> D['e']

Traceback (most recent call last):
  File "<pyshell#295>", line 1, in <module>
    D['e']
KeyError: 'e'
>>> 
>>> D.get('a', 'missing')
1
>>> D.get('e', 'missing')
'missing'
>>> 
>>> dir
<built-in function dir>
>>> dir(D)
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
>>> 
>>> 
>>> T = (1, 2, 3, 4)
>>> 
>>> T[0]
1
>>> T + (8, 9)
(1, 2, 3, 4, 8, 9)
>>> 
>>> T{0] = 99
SyntaxError: invalid syntax
>>> 
>>> T[0] = 99

Traceback (most recent call last):
  File "<pyshell#311>", line 1, in <module>
    T[0] = 99
TypeError: 'tuple' object does not support item assignment
>>> 
>>> T + (8, 9)
(1, 2, 3, 4, 8, 9)
>>> T
(1, 2, 3, 4)
>>> 
>>> 
>>> 
>>> F = open('data.txt', 'w')
>>> F.write('Hello\n')
>>> F.write('world.\n')
>>> F.close()
>>> 
>>> F = open('data.txt')
>>> bytes = F.read()
>>> bytes
'Hello\nworld.\n'
>>> print bytes
Hello
world.

>>> F = open('data.txt')
>>> F.readline()
'Hello\n'
>>> F.readline()
'world.\n'
>>> F.readline()
''
>>> 
>>> F = open('data.txt')
>>> F.readlines()
['Hello\n', 'world.\n']
>>> 
>>> 
>>> import struct
>>> 
>>> F = open('data.bin', 'wb')
>>> data = struct.pack('>i4sh', 8, 'spam', 7)
>>> data
'\x00\x00\x00\x08spam\x00\x07'
>>> F.write(data)
>>> F.close()
>>> 
>>> F = open('data.bin', 'rb')
>>> bytes = F.read()
>>> bytes
'\x00\x00\x00\x08spam\x00\x07'
>>> 
>>> vals = struct.unpack('>i4sh', bytes)
>>> vals
(8, 'spam', 7)
>>> 
>>> vals = list(vals)
>>> vals
[8, 'spam', 7]
>>> 
>>> L = [1, 2, 3, 4, 5]
>>> fmt = 'i' * len(L)
>>> fmt
'iiiii'
>>> struct.pack(fmt, *L)
'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00'
>>> 
>>> 
>>> X = None
>>> L = []
>>> L[99] = 1

Traceback (most recent call last):
  File "<pyshell#362>", 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]
>>> 
>>> msg = '''
xxxxxxxxx
xxxxxxxxxxxxxx'''
>>> 
>>> msg
'\nxxxxxxxxx\nxxxxxxxxxxxxxx'
>>> 'aa'  'bbb'   'cc'
'aabbbcc'
>>> msg = ('aa'
       'bbb'
          'cc')
>>> msg
'aabbbcc'
>>> 
>>> inp = raw_input('Enter:')
Enter:abcdefg
>>> inp
'abcdefg'
>>> ================================ RESTART ================================
>>> 
Enter age:40
4040404040404040
Enter age:50
5050505050505050
Enter age:stop
bye
>>> ================================ RESTART ================================
>>> 
Enter age:4
16
Enter age:40
1600
Enter age:50
2500
Enter age:stop
bye
>>> ================================ RESTART ================================
>>> 
Enter age:abc

Traceback (most recent call last):
  File "C:/Python25/interact.py", line 4, in <module>
    print int(inp) ** 2
ValueError: invalid literal for int() with base 10: 'abc'
>>> S = 'abc'
>>> S.isdigit()
False
>>> ================================ RESTART ================================
>>> 
Enter age:40
1600
Enter age:abc
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Enter age:7
49
Enter age:stop
bye
>>> 
>>> 
>>> XYZ

Traceback (most recent call last):
  File "<pyshell#384>", line 1, in <module>
    XYZ
NameError: name 'XYZ' is not defined
>>> 
>>> 
>>> X = Y = 0
>>> 
>>> X = X + 1
>>> X
1
>>> Y
0
>>> 
>>> X = Y = []
>>> X.append(99)
>>> X
[99]
>>> Y
[99]
>>> 
>>> X, Y = [], []
>>> X.append(99)
>>> X
[99]
>>> Y
[]
>>> a, b, c = 'xx', 'yy', 'zz'
>>> a
'xx'
>>> b
'yy'
>>> c
'zz'
>>> 
>>> spam, ham = 'yum', 'YUM'
>>> spam
'yum'
>>> ham
'YUM'
>>> 
>>> (spam, ham) = ('yum', 'YUM')
>>> 

>>> L = [1, 2, 3]
>>> L.append($)
SyntaxError: invalid syntax
>>> 
>>> L.append(4)
>>> L
[1, 2, 3, 4]
>>> 
>>> L = L.append(5)
>>> print L
None
>>> 
>>> 
>>> D

Traceback (most recent call last):
  File "<pyshell#423>", line 1, in <module>
    D
NameError: name 'D' is not defined
>>> 
>>> D = {'a':1, 'b':2, 'c':3}
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> for key in D.keys().sort():
	print key, D[key]

	

Traceback (most recent call last):
  File "<pyshell#430>", line 1, in <module>
    for key in D.keys().sort():
TypeError: 'NoneType' object is not iterable
>>> 
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> sorted(D)
['a', 'b', 'c']
>>> for key in sorted(D):
	print key, D[key]

	
a 1
b 2
c 3
>>> 
>>> 
>>> 
>>> import sys
>>> print >> sys.stderr, 'Bad!' * 20
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
>>> 
>>> 
>>> tmp = sys.stdout
>>> sys.stdout = open('output')
>>> print 'spam'

Traceback (most recent call last):
  File "<pyshell#446>", line 1, in <module>
    print 'spam'
IOError: [Errno 0] Error
>>> 
>>> sys.stdout = open('output', 'w')
>>> print 'spam'
>>> pribt 99
SyntaxError: invalid syntax
>>> 
>>> print 99
>>> 
>>> sys.stdout.close()
>>> sys.stdout = tmp
>>> print 42
42
>>> 
>>> print open('output'().read()
	   
KeyboardInterrupt
>>> 
>>> print open('output').read()
spam
99

>>> print(a, b, c, end='', sep='', file=sys.stderr) 
KeyboardInterrupt
>>> 
>>> ord('s')
115
>>> 
>>> ord('spam')

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

	
115
112
97
109
>>> 

>>> 
>>> 
