2013-11-29 | Paul Boddie | file changeset files shortlog | Added an example of a method with an uncertain default parameter value. | syspython-as-target |
paul@754 | 1 | #!/usr/bin/env python |
paul@754 | 2 | |
paul@754 | 3 | switch = 0 |
paul@754 | 4 | |
paul@754 | 5 | class C: |
paul@754 | 6 | |
paul@754 | 7 | if switch: |
paul@754 | 8 | default = 100 |
paul@754 | 9 | else: |
paul@754 | 10 | default = 101 |
paul@754 | 11 | |
paul@754 | 12 | def f(self, x=default): |
paul@754 | 13 | return x |
paul@754 | 14 | |
paul@754 | 15 | c = C() |
paul@754 | 16 | result_101 = c.f() |
paul@754 | 17 | result_202 = c.f(202) |
paul@754 | 18 | |
paul@754 | 19 | # vim: tabstop=4 expandtab shiftwidth=4 |