Last login: Tue Oct 28 08:25:10 on ttys000 fantazja-2:~ wasylkowski$ cd python fantazja-2:python wasylkowski$ python script.py hello world fantazja-2:python wasylkowski$ python Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print "hello world" hello world >>> fantazja-2:python wasylkowski$ python --version Python 2.6 fantazja-2:python wasylkowski$ python Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> 2 * 4 8 >>> 4 / 3 1 >>> 4.0 /3 1.3333333333333333 >>> >>> >>> x = 4.0 >>> y Traceback (most recent call last): File "", line 1, in NameError: name 'y' is not defined >>> y = 4 >>> y = "sdfjlsdfj" >>> >>> str = "this is a string" >>> str = 'this is a string' >>> str = """this is a string""" >>> >>> str "that's it" File "", line 1 str "that's it" ^ SyntaxError: invalid syntax >>> str = "that's it" >>> str = '"lll"' >>> str '"lll"' >>> "hello " "world" 'hello world' >>> >>> "hello" + "world" 'helloworld' >>> "ha" * 6 'hahahahahaha' >>> str = "abcdefg" >>> str 'abcdefg' >>> str[4] 'e' >>> str[0] 'a' >>> str[0] = "w" Traceback (most recent call last): File "", line 1, in TypeError: 'str' object does not support item assignment >>> str[1:4] 'bcd' >>> str[-1] 'g' >>> str 'abcdefg' >>> str[-2] 'f' >>> str[-4:-2] 'de' >>> str[1:100:2] 'bdf' >>> l = [1, 2, 3, 4, 5] >>> l [1, 2, 3, 4, 5] >>> l[1:100:2] [2, 4] >>> l[0:100:2] [1, 3, 5] >>> >>> l = [1, 2, 3.0, "str", [1,2,3],4] >>> l [1, 2, 3.0, 'str', [1, 2, 3], 4] >>> l[2] 3.0 >>> l[3] 'str' >>> >>> l * 5 [1, 2, 3.0, 'str', [1, 2, 3], 4, 1, 2, 3.0, 'str', [1, 2, 3], 4, 1, 2, 3.0, 'str', [1, 2, 3], 4, 1, 2, 3.0, 'str', [1, 2, 3], 4, 1, 2, 3.0, 'str', [1, 2, 3], 4] >>> l [1, 2, 3.0, 'str', [1, 2, 3], 4] >>> l[3] = 19 >>> l [1, 2, 3.0, 19, [1, 2, 3], 4] >>> l[2:4] = [] >>> l [1, 2, [1, 2, 3], 4] >>> (1,2,3) (1, 2, 3) >>> x = (1,2,3) >>> x (1, 2, 3) >>> a,b,c = x >>> a 1 >>> b 2 >>> c 3 >>> x = set([1,2,3,4]) >>> y = set([3,4,5,6]) >>> x set([1, 2, 3, 4]) >>> y set([3, 4, 5, 6]) >>> x & y set([3, 4]) >>> x | y set([1, 2, 3, 4, 5, 6]) >>> x - y set([1, 2]) >>> x ^ y set([1, 2, 5, 6]) >>> >>> dict = {"john" : 2737, "alice" : 12} >>> dict {'john': 2737, 'alice': 12} >>> dict["john"] 2737 >>> dict["john"] = 8 >>> dict {'john': 8, 'alice': 12} >>> dict[8] = 3.4 >>> dict {8: 3.3999999999999999, 'john': 8, 'alice': 12} >>> >>> x set([1, 2, 3, 4]) >>> del x >>> x Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined >>> l [1, 2, [1, 2, 3], 4] >>> del l[1] >>> l [1, [1, 2, 3], 4] >>> del dict["john"] >>> dict {8: 3.3999999999999999, 'alice': 12} >>> l = [1,2,3,4,5] >>> [x * x for x in l] [1, 4, 9, 16, 25] >>> [[x, 2 ** x] for x in l] [[1, 2], [2, 4], [3, 8], [4, 16], [5, 32]] >>> [str(round(355/113.0)) for i in range(1,5)] Traceback (most recent call last): File "", line 1, in TypeError: 'str' object is not callable >>> del str>>> [str(round(355/113.0)) for i in range(1,5)] ['3.0', '3.0', '3.0', '3.0'] >>> [str(round(355/113.0, i)) for i in range(1,5)] ['3.1', '3.14', '3.142', '3.1416'] >>> [str(round(355/113.0, i)) for i in range(1,7)] ['3.1', '3.14', '3.142', '3.1416', '3.14159', '3.141593'] >>> >>> [str(round(355/113.0, i)) for i in range(1,30)] ['3.1', '3.14', '3.142', '3.1416', '3.14159', '3.141593', '3.1415929', '3.14159292', '3.14159292', '3.1415929204', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035', '3.14159292035'] >>> x = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9] ... ] >>> x [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> [[row[i] for row in mat] for i in [0,1,2]] Traceback (most recent call last): File "", line 1, in NameError: name 'mat' is not defined >>> [[row[i] for row in x] for i in [0,1,2]] [[1, 4, 7], [2, 5, 8], [3, 6, 9]] >>> >>> fantazja-2:python wasylkowski$ python script.py > 4 done fantazja-2:python wasylkowski$ python script.py done fantazja-2:python wasylkowski$ python script.py fantazja-2:python wasylkowski$ python script.py File "script.py", line 3 print "> 4" ^ IndentationError: expected an indented block fantazja-2:python wasylkowski$ python script.py > 4 done fantazja-2:python wasylkowski$ python script.py Enter a number: 8 small number fantazja-2:python wasylkowski$ python script.py Enter a number: 12 large number fantazja-2:python wasylkowski$ python script.py File "script.py", line 2 if x = 4: ^ SyntaxError: invalid syntax fantazja-2:python wasylkowski$ python script.py Enter a number: 5 fantazja-2:python wasylkowski$ python Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> l = [1,2,3,4,5] >>> for x in l: ... print l ... [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] >>> l = [1,2,3,4,5] >>> for x in l: ... print x ... 1 2 3 4 5 >>> for x in range(0,10): ... print x ... 0 1 2 3 4 5 6 7 8 9 >>> for x in range(0,10,2): ... print x ... 0 2 4 6 8 >>> l [1, 2, 3, 4, 5] >>> for x in l: ... l.append (2 ** x) ... ^CTraceback (most recent call last): File "", line 2, in KeyboardInterrupt >>> for x in l[:]: ... KeyboardInterrupt >>> l = [1,2,3,4,5] >>> for x in l[:]: ... l.append (2 ** x) ... >>> l [1, 2, 3, 4, 5, 2, 4, 8, 16, 32] >>> fantazja-2:python wasylkowski$ python script.py 2 is prime 3 is prime 4 divides by 2 5 is prime 6 divides by 2 7 is prime 8 divides by 2 9 divides by 3 fantazja-2:python wasylkowski$ python script.py 8 fantazja-2:python wasylkowski$ python Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import script 8 >>> help (add) Traceback (most recent call last): File "", line 1, in NameError: name 'add' is not defined >>> from script import * >>> help (add) >>> >>> help (list.append) >>> help (list) >>> >>> >>> g = 10 >>> def f (): ... g = 8 ... >>> g 10 >>> f() >>> g 10 >>> def (): File "", line 1 def (): ^ SyntaxError: invalid syntax >>> def f (): ... global g ... g = 8 ... >>> f() >>> g 8 >>> f >>> f() >>> None >>> x = f() >>> x >>> print x None >>> >>> def f (x, y = 8): ... return x + y ... >>> f (10) 18 >>> f\ ... >>> f >>> def f (x, y): ... return x + y ... >>> def apply (fun, x, y): ... fun (x, y) ... >>> apply (f, 2, 4) >>> >>> def apply (fun, x, y): ... return fun (x, y) ... >>> apply (f, 2, 4) 6 >>> >>> lambda x : x + 2 at 0xbb1f70> >>> def apply (f, x): ... return f (x) ... >>> apply (lambda x : x + 2, 8) 10 >>> >>> def f (*args): ... print args ... >>> f (1,2,3,4) (1, 2, 3, 4) >>> f (1,2, "fsdlfkj") (1, 2, 'fsdlfkj') >>> def addtocache (x, cache = []): ... cache.append (x) ... print cache ... >>> cache = [1,2] >>> addtocache (8, cache) [1, 2, 8] >>> addtocache ("str", cache) [1, 2, 8, 'str'] >>> addtocache ("str") ['str'] >>> addtocache (8) ['str', 8] >>> >>> def addtocache (x, cache = None): ... if cache == None: ... cache = [] ... >>> >>> >>> def f (x): ... return x ... >>> f >>> f (7) 7 >>> def f(x, y): ... return x + y ... f File "", line 3 f ^ SyntaxError: invalid syntax >>> def f(x, y): ... return x + y ... >>> f >>> f(2) Traceback (most recent call last): File "", line 1, in TypeError: f() takes exactly 2 arguments (1 given) >>> f >>> t = f >>> t(2, 4) 6 >>> True True >>> False False >>> not True False >>> del t >>> f >>> reload (script) >>> A Traceback (most recent call last): File "", line 1, in NameError: name 'A' is not defined >>> A = script.A >>> A >>> A.i 12345 >>> A.l = 8 >>> A >>> A.l 8 >>> del A.i >>> A >>> A.i Traceback (most recent call last): File "", line 1, in AttributeError: class A has no attribute 'i' >>> a = A() >>> a.f(8) 8 >>> A.f >>> A.f (2, 3) Traceback (most recent call last): File "", line 1, in TypeError: unbound method f() must be called with A instance as first argument (got int instance instead) >>> A.f (A(), 3) 3 >>> def g (self): ... print self ... >>> A.t = g >>> a = A() >>> a.t() >>> a1 = A() >>> a2 = A() >>> a1.f(2) 2 >>> a2.f(2) 2 >>> A.f(a1, 2) 2 >>> reload (script) >>> A = script.A >>> new A() File "", line 1 new A() ^ SyntaxError: invalid syntax >>> a = A() >>> a.i 8 >>> A.i 12345 >>> >>> a.f > >>> x = a.f >>> x(2) 2 >>> fantazja-2:python wasylkowski$ python script.py Enter: 9 OK Always happens fantazja-2:python wasylkowski$ python script.py Enter: sdjfk Wrong! Always happens fantazja-2:python wasylkowski$ python script.py Enter: ^CWrong! Always happens fantazja-2:python wasylkowski$ python script.py Wrong! Always happens fantazja-2:python wasylkowski$ python script.py Enter: sdfg Wrong! invalid literal for int() with base 10: 'sdfg' Always happens fantazja-2:python wasylkowski$ ls p1 fantazja-2:python wasylkowski$ python Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 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', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'py3kwarning', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions'] >>> sys.version '2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) \n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]' >>> >>> ls Traceback (most recent call last): File "", line 1, in NameError: name 'ls' is not defined >>> import p1.s1.m1.add Traceback (most recent call last): File "", line 1, in ImportError: No module named p1.s1.m1.add >>> import p1 Traceback (most recent call last): File "", line 1, in ImportError: No module named p1 >>> import p1 >>> import p1.s1 Traceback (most recent call last): File "", line 1, in ImportError: No module named s1 >>> import p1.s1 >>> import p1.s1.m1 >>> import p1.s1.m1.add Traceback (most recent call last): File "", line 1, in ImportError: No module named add >>> import p1.s1.m1 >>> p1.s1.m1.add (2, 3) 5 >>> from p1.s1.m1 import add >>> add (2,3) 5 >>> from p1.s1.m1 import * >>> add (2,3) 5 >>> from p1 import * >>> dir (p1) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 's1'] >>> s1 >>> from script import * >>> A >>> A.f >>> A.__g Traceback (most recent call last): File "", line 1, in AttributeError: class A has no attribute '__g' >>> dir (A) ['_A__g', '__doc__', '__module__', 'f'] >>> A._A__g >>> A()._A__g() g >>> help (A) >>>