{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def foo(a, b):\n", " global c\n", " \n", " print '1', a, b\n", " a = 'yes'\n", " b = 'yes yes'\n", " #print '1.5', c\n", " c = 'maybe'\n", " print '1.6', c\n", " print '2', a, b\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c = 'no'\n", "d = 'nono'\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3 no nono\n", "1 no nono\n", "1.6 maybe\n", "2 yes yes yes\n", "4 maybe nono\n" ] } ], "source": [ "print '3', c, d\n", "foo(c, d)\n", "print '4', c, d" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import datetime" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def goo(a=datetime.datetime.now):\n", " try:\n", " b = a()\n", " except TypeError:\n", " b = a\n", " print 'a is', repr(a), 'b is', b" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a is b is 2014-11-08 10:51:35.073836\n" ] } ], "source": [ "goo()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a is 'world' b is world\n" ] } ], "source": [ "goo('world')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a is 5 b is 5\n" ] } ], "source": [ "goo(5)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a is {'hello': 'world'} b is {'hello': 'world'}\n" ] } ], "source": [ "goo({'hello': 'world'})" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }