annotate python/example/ternary.py @ 541:776d83eb0fd9

python/example/ternary.py
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 Sep 2013 13:02:36 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
541
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 illustrates python ternary is smart about branching
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 class Foo(object):
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 def __init__(self):
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 print 'hi'
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 bar = 1
776d83eb0fd9 python/example/ternary.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 print Foo() if bar is None else bar