Facebook
From rrb, 9 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 94
  1. Python 3.6.5 (default, Jul 16 2018, 18:58:26)
  2. [GCC 5.5.0] on linux
  3. Type "copyright", "credits" or "license()" for more information.
  4. >>> def function(x,*z): print(x,z)
  5.  
  6. >>> function(1)
  7. 1 ()
  8. >>> def function(x,y,*z): print(x,y,z)
  9.  
  10. >>> function(1)
  11. Traceback (most recent call last):
  12.   File "<pyshell#6>", line 1, in <module>
  13.     function(1)
  14. TypeError: function() missing 1 required positional argument: 'y'
  15. >>> def function(x,y=2,*z): print(x,y,z)
  16.  
  17. >>> function(1)
  18. 1 2 ()
  19. >>> function(1,3)
  20. 1 3 ()
  21. >>> function(1,3,4)
  22. 1 3 (4,)
  23. >>> function(1,3,z=(3,))
  24. Traceback (most recent call last):
  25.   File "<pyshell#12>", line 1, in <module>
  26.     function(1,3,z=(3,))
  27. TypeError: function() got an unexpected keyword argument 'z'
  28. >>> function(1,3,*z=(3,))
  29. SyntaxError: invalid syntax
  30. >>> function(1,3,z=3)
  31. Traceback (most recent call last):
  32.   File "<pyshell#14>", line 1, in <module>
  33.     function(1,3,z=3)
  34. TypeError: function() got an unexpected keyword argument 'z'
  35. >>> function(1,3)
  36. 1 3 ()
  37. >>> def f(x,y=2,*z,l=9)
  38. SyntaxError: invalid syntax
  39. >>> def f(x,y=2,*z,l=9): print(x,y,z,l);
  40.  
  41. >>> f()
  42. Traceback (most recent call last):
  43.   File "<pyshell#21>", line 1, in <module>
  44.     f()
  45. TypeError: f() missing 1 required positional argument: 'x'
  46. >>> f(2)
  47. 2 2 () 9
  48. >>> f(2,l=list('abcde'))
  49. 2 2 () ['a', 'b', 'c', 'd', 'e']
  50. >>> f(2,3,4l=list('abcde'))
  51. SyntaxError: invalid syntax
  52. >>> f(2,3,4,l=list('abcde'))
  53. 2 3 (4,) ['a', 'b', 'c', 'd', 'e']
  54. >>> def f(x,y=2,**z,l=9): print(x,y,z,l);
  55. SyntaxError: invalid syntax
  56. >>> def f(x,y=2,*z,l): print(x,y,z,l);
  57.  
  58. >>> f(2)
  59. Traceback (most recent call last):
  60.   File "<pyshell#29>", line 1, in <module>
  61.     f(2)
  62. TypeError: f() missing 1 required keyword-only argument: 'l'
  63. >>> f(2,l=5)
  64. 2 2 () 5
  65. >>> def f(x,y=2,*z,l,**klucze): print(x,y,z,l,klucze)
  66.  
  67. >>> def f(x,y=2,*z,l,**klucze): print(x,y,z,l,klucze)f(2,l=5)
  68. KeyboardInterrupt
  69. >>> f(*list(range(8)),l=5)
  70. 0 1 (2, 3, 4, 5, 6, 7) 5 {}
  71. >>> f(*list(range(8)),l=5,**globals())
  72. 0 1 (2, 3, 4, 5, 6, 7) 5 {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'function': <function function at 0x7f6526f13a60>, 'f': <function f at 0x7f6526f13c80>}
  73. >>> f(*list(range(8)),l=5,globals())
  74. SyntaxError: positional argument follows keyword argument
  75. >>> f(list(range(8)),l=5,globals())
  76. SyntaxError: positional argument follows keyword argument
  77. >>> f(list(range(8)),l=5)
  78. [0, 1, 2, 3, 4, 5, 6, 7] 2 () 5 {}
  79. >>> f(*list(range(8)),l=5)
  80. 0 1 (2, 3, 4, 5, 6, 7) 5 {}
  81. >>> f(*globals(),l=5)
  82. __name__ __doc__ ('__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', 'function', 'f') 5 {}
  83. >>> s = globals()
  84. >>> s
  85. {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'function': <function function at 0x7f6526f13a60>, 'f': <function f at 0x7f6526f13c80>, 's': {...}}
  86. >>> for x in s :
  87.         print(x)
  88.  
  89.        
  90. __name__
  91. Traceback (most recent call last):
  92.   File "<pyshell#44>", line 1, in <module>
  93.     for x in s :
  94. RuntimeError: dictionary changed size during iteration
  95. >>> s = globals().copy()
  96. >>> for x in s :
  97.         print(x)
  98.  
  99.        
  100. __name__
  101. __doc__
  102. __package__
  103. __loader__
  104. __spec__
  105. __annotations__
  106. __builtins__
  107. function
  108. f
  109. s
  110. x
  111. >>>
  112. >>> def f(x,y=2,*z,l,**klucze): print(x,y,z,l,klucze)
  113.  
  114. >>> def f(x,y=2,*,l,**klucze): print(x,y,z,l,klucze)
  115.  
  116. >>> f(*globals(),l=5)
  117. Traceback (most recent call last):
  118.   File "<pyshell#53>", line 1, in <module>
  119.     f(*globals(),l=5)
  120. TypeError: f() takes from 1 to 2 positional arguments but 11 positional arguments (and 1 keyword-only argument) were given
  121. >>> f(globals(),l=5)
  122. Traceback (most recent call last):
  123.   File "<pyshell#54>", line 1, in <module>
  124.     f(globals(),l=5)
  125.   File "<pyshell#52>", line 1, in f
  126.     def f(x,y=2,*,l,**klucze): print(x,y,z,l,klucze)
  127. NameError: name 'z' is not defined
  128. >>> def f(x,y=2,*,l,**klucze): print(x,y,l,klucze)
  129.  
  130. >>> f(globals(),l=5)
  131. {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'function': <function function at 0x7f6526f13a60>, 'f': <function f at 0x7f6526f13f28>, 's': {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'function': <function function at 0x7f6526f13a60>, 'f': <function f at 0x7f6526f13c80>, 's': {...}, 'x': '__name__'}, 'x': 'x'} 2 5 {}
  132. >>>
  133. >>>
  134. >>>
  135. >>>
  136. >>> def m( x ) :
  137.         return x**3.2
  138.  
  139. >>> m(9)
  140. 1131.2954233842977
  141. >>> l = list(range(9))
  142. >>> l
  143. [0, 1, 2, 3, 4, 5, 6, 7, 8]
  144. >>> for x in l :
  145.         print(m(x))
  146.  
  147.        
  148. 0.0
  149. 1.0
  150. 9.18958683997628
  151. 33.63473536961897
  152. 84.44850628946526
  153. 172.4662076826519
  154. 309.0893215187353
  155. 506.19019442693155
  156. 776.0468820533241
  157. >>> map(m,l)
  158. <map object at 0x7f6521480f28>
  159. >>> list(_)
  160. [0.0, 1.0, 9.18958683997628, 33.63473536961897, 84.44850628946526, 172.4662076826519, 309.0893215187353, 506.19019442693155, 776.0468820533241]
  161. >>> _
  162. [0.0, 1.0, 9.18958683997628, 33.63473536961897, 84.44850628946526, 172.4662076826519, 309.0893215187353, 506.19019442693155, 776.0468820533241]
  163. >>> map(m,*l)
  164. Traceback (most recent call last):
  165.   File "<pyshell#74>", line 1, in <module>
  166.     map(m,*l)
  167. TypeError: 'int' object is not iterable
  168. >>>
  169. >>>
  170. >>> help(map)\
  171.  
  172.    
  173. Help on class map in module builtins:
  174.  
  175. class map(object)
  176.  |  map(func, *iterables) --> map object
  177.  |  
  178.  |  Make an iterator that computes the function using arguments from
  179.  |  each of the iterables.  Stops when the shortest iterable is exhausted.
  180.  |  
  181.  |  Methods defined here:
  182.  |  
  183.  |  __getattribute__(self, name, /)
  184.  |      Return getattr(self, name).
  185.  |  
  186.  |  __iter__(self, /)
  187.  |      Implement iter(self).
  188.  |  
  189.  |  __new__(*args, **kwargs) from builtins.type
  190.  |      Create and return a new object.  See help(type) for accurate signature.
  191.  |  
  192.  |  __next__(self, /)
  193.  |      Implement next(self).
  194.  |  
  195.  |  __reduce__(...)
  196.  |      Return state information for pickling.
  197.  
  198. >>> list(map(m,map(m,l)))
  199. [0.0, 1.0, 1209.33648530384, 76863.76406798889, 1462494.7346870452, 14369870.171516128, 92954154.28520527, 450613220.96196795, 1768648242.2218032]
  200. >>>
  201.  
  202. >>>
  203. a
  204. Traceback (most recent call last):
  205.   File "<pyshell#81>", line 2, in <module>
  206.     a
  207. NameError: name 'a' is not defined
  208. >>>
  209.