{
 "metadata": {
  "name": "python [exp|op]s"
 }, 
 "nbformat": 2, 
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "print 5<23<42", 
      "print 5>23>42"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "True", 
        "False"
       ]
      }
     ], 
     "prompt_number": 33
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "print 'igaz' if True else 'hamis'"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "igaz"
       ]
      }
     ], 
     "prompt_number": 37
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "print 'hell' in 'hello world!'", 
      "print 'heaven' not in 'hello world!'"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "True", 
        "True"
       ]
      }
     ], 
     "prompt_number": 38
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "tdict={'a': [1,2,3,4],", 
      "       'b': None}", 
      "for k,v in tdict.items():", 
      "    print k, v or 'unknown'"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "a [1, 2, 3, 4]", 
        "b unknown"
       ]
      }
     ], 
     "prompt_number": 39
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "print \"%s %s %0.2f |%4s|\" % ('a','asdf', 6.2830, \"a\")", 
      "print \"%(short)s %(str)s %(num)0.2f |%(short)4s|\" % {'str': 'asdf', 'num': 6.283, 'short': 'a'}", 
      "print \"{short} {str} {num:>.3g} |{short:>4s}|\".format(str='asdf', num=6.283, short='a')"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "a asdf 6.28 |   a|", 
        "a asdf 6.28 |   a|", 
        "a asdf 6.28 |   a|"
       ]
      }
     ], 
     "prompt_number": 40
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "def plus1(x):", 
      "    return x+1", 
      "print map(plus1, [1,2,3,4])"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "[2, 3, 4, 5]"
       ]
      }
     ], 
     "prompt_number": 42
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "print map(lambda x: x+1, [1,2,3,4])", 
      "print [x+1 for x in [1,2,3,4]]"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "[2, 3, 4, 5]", 
        "[2, 3, 4, 5]"
       ]
      }
     ], 
     "prompt_number": 43
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "print [a**2 for a in [1,2,3,4] if a%2]", 
      "print {chr(a+65): 1.0/a for a in [1,2,3,4] if not a%2}"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "[1, 9]", 
        "{'C': 0.5, 'E': 0.25}"
       ]
      }
     ], 
     "prompt_number": 44
    }, 
    {
     "cell_type": "code", 
     "collapsed": true, 
     "input": [
      "if True:", 
      "    pass", 
      "elif True:", 
      "    pass", 
      "elif True:", 
      "    pass", 
      "else:", 
      "    pass"
     ], 
     "language": "python", 
     "outputs": [], 
     "prompt_number": 28
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "for i, v in enumerate(['a','b','c']):", 
      "    print i, v", 
      "    if i>10: break", 
      "else:", 
      "    print 'final'"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "0 a", 
        "1 b", 
        "2 c", 
        "final"
       ]
      }
     ], 
     "prompt_number": 45
    }, 
    {
     "cell_type": "code", 
     "collapsed": true, 
     "input": [
      "while True:", 
      "    if True: break", 
      "else:", 
      "    print 'not now!'"
     ], 
     "language": "python", 
     "outputs": [], 
     "prompt_number": 47
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "if=4", 
      "if if==4:", 
      "    print if"
     ], 
     "language": "python", 
     "outputs": [
      {
       "ename": "SyntaxError", 
       "evalue": "invalid syntax (<ipython-input-41-fc16a4d4b746>, line 1)", 
       "output_type": "pyerr", 
       "traceback": [
        "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-41-fc16a4d4b746>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    if=4\u001b[0m\n\u001b[1;37m      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
       ]
      }
     ], 
     "prompt_number": 41
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "segal=['foo', 'bar', 'baz', 'foo', 'foo', 'bar','foo']", 
      "for i, v in enumerate(segal):", 
      "    print 'ok' if segal[i-1]=='foo' and v in ['bar', 'baz'] else 'frmbl-grmbl'"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "frmbl-grmbl", 
        "ok", 
        "frmbl-grmbl", 
        "frmbl-grmbl", 
        "frmbl-grmbl", 
        "ok", 
        "frmbl-grmbl"
       ]
      }
     ], 
     "prompt_number": 48
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "class point(object):", 
      "    ", 
      "    def __init__(self, x, y):", 
      "        self.name='fix asdf'", 
      "        self.__dict__['x']=x", 
      "        self.__dict__['y']=y", 
      "        ", 
      "    def __getattr__(self, name):", 
      "        if name in self.__dict__:", 
      "            return self.__dict__[name]", 
      "        elif name=='virtual':", 
      "            return self.__dict__['x']-self.__dict__['y']", 
      "        else:", 
      "            raise KeyError", 
      "            ", 
      "    def distance(self,other):", 
      "        return sqrt((self.x-other.x)**2 + (self.y-other.y)**2)", 
      "        ", 
      "p=point(0,1)", 
      "print p.x, p.virtual", 
      "p2=point(2,5)", 
      "p.distance(p2)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "0 -1"
       ]
      }, 
      {
       "output_type": "pyout", 
       "prompt_number": 56, 
       "text": [
        "4.4721359549995796"
       ]
      }
     ], 
     "prompt_number": 56
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "import math", 
      "class kor(point):", 
      "    def __init__(self, x, y, r):", 
      "        self.__dict__['r']=r", 
      "        super(kor, self).__init__(x,y)", 
      "    def __getattr__(self, name):", 
      "        if name=='area':", 
      "            return self.r**2*math.pi", 
      "        super(kor, self).__getattr__(name)", 
      "", 
      "class negyzet(point):", 
      "    def __init__(self, x, y, l):", 
      "        self.__dict__['l']=l", 
      "        super(negyzet, self).__init__(x,y)", 
      "    def __getattr__(self, name):", 
      "        if name=='area':", 
      "            return self.l**2", 
      "        super(negyzet, self).__getattr__(name)", 
      "k=kor(4,4,4)", 
      "print k.x, k.y, k.r", 
      "print k.distance(p2)", 
      "print k.area", 
      "n=negyzet(5,5,5)", 
      "n.distance(k)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "4 4 4", 
        "2.2360679775", 
        "50.2654824574"
       ]
      }, 
      {
       "output_type": "pyout", 
       "prompt_number": 64, 
       "text": [
        "1.4142135623730951"
       ]
      }
     ], 
     "prompt_number": 64
    }, 
    {
     "cell_type": "code", 
     "collapsed": true, 
     "input": [], 
     "language": "python", 
     "outputs": []
    }
   ]
  }
 ]
}