2017-03-10 | Paul Boddie | file changeset files shortlog | Merged changes from the default branch. | normal-function-parameters |
paul@2 | 1 | def f(): |
paul@2 | 2 | l = [1, 2, 3] |
paul@2 | 3 | x = l |
paul@2 | 4 | a, b, c = l |
paul@2 | 5 | d, e, f = [1, 2, 3] |
paul@243 | 6 | print a, b, c # 1, 2, 3 |
paul@243 | 7 | print d, e, f # 1, 2, 3 |
paul@243 | 8 | print x # [1, 2, 3] |
paul@2 | 9 | |
paul@2 | 10 | def g(x): |
paul@2 | 11 | l = [1, 2, 3] |
paul@2 | 12 | m = [4, l, 6] |
paul@2 | 13 | if x: |
paul@2 | 14 | n = l |
paul@2 | 15 | else: |
paul@2 | 16 | n = m |
paul@173 | 17 | print n |
paul@2 | 18 | |
paul@560 | 19 | def h(): |
paul@560 | 20 | return 7, 8, 9 |
paul@560 | 21 | |
paul@561 | 22 | def i(): |
paul@561 | 23 | a, b, c = h() |
paul@561 | 24 | print a, b, c |
paul@561 | 25 | |
paul@561 | 26 | # Test assignment operations within functions. |
paul@561 | 27 | |
paul@197 | 28 | f() |
paul@243 | 29 | g(0) # [4, [1, 2, 3], 6] |
paul@243 | 30 | g(1) # [1, 2, 3] |
paul@197 | 31 | |
paul@561 | 32 | # Test aliasing, assignment of list elements and direct assignment of elements. |
paul@561 | 33 | |
paul@2 | 34 | l = [1, 2, 3] |
paul@2 | 35 | x = l |
paul@2 | 36 | a, b, c = l |
paul@2 | 37 | d, e, f = [1, 2, 3] |
paul@560 | 38 | |
paul@560 | 39 | print a, b, c # 1 2 3 |
paul@560 | 40 | print d, e, f # 1 2 3 |
paul@243 | 41 | print x # [1, 2, 3] |
paul@560 | 42 | |
paul@561 | 43 | # Test embedding of sequences in sequences. |
paul@561 | 44 | |
paul@2 | 45 | m = [4, l, 6] |
paul@561 | 46 | |
paul@561 | 47 | # Test sequence truth value interpretation. |
paul@561 | 48 | |
paul@2 | 49 | if x: |
paul@2 | 50 | n = l |
paul@2 | 51 | else: |
paul@2 | 52 | n = m |
paul@560 | 53 | |
paul@243 | 54 | print n # [1, 2, 3] |
paul@560 | 55 | |
paul@561 | 56 | # Test temporary variable usage at module level. |
paul@561 | 57 | |
paul@560 | 58 | a, b, c = h() |
paul@560 | 59 | print a, b, c # 7 8 9 |
paul@561 | 60 | |
paul@561 | 61 | # Test temporary variable usage in functions. |
paul@561 | 62 | |
paul@561 | 63 | i() # 7 8 9 |
paul@561 | 64 | |
paul@561 | 65 | # Test temporary variable usage in classes. |
paul@561 | 66 | |
paul@561 | 67 | class C: |
paul@561 | 68 | a, b, c = h() |
paul@561 | 69 | print a, b, c # 7 8 9 |