From e7c1d50e067732a6fe7e91ff405c21c4e610b61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 20 Jun 2022 22:20:07 +0200 Subject: [PATCH] A lot of changes in Arguments and Inline --- README.md | 66 ++++++++++++++++++++++---------------------- index.html | 80 +++++++++++++++++++++++++++--------------------------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 5b1ae77..950b105 100644 --- a/README.md +++ b/README.md @@ -668,16 +668,16 @@ Arguments --------- ### Inside Function Call ```python -() # f(0, 0) -() # f(x=0, y=0) -(, ) # f(0, y=0) +func() # func(1, 2) +func() # func(x=1, y=2) +func(, ) # func(1, y=2) ``` ### Inside Function Definition ```python -def f(): # def f(x, y): -def f(): # def f(x=0, y=0): -def f(, ): # def f(x, y=0): +def func(): ... # def func(x, y): ... +def func(): ... # def func(x=0, y=0): ... +def func(, ): ... # def func(x, y=0): ... ``` * **Default values are evaluated when function is first encountered in the scope.** * **Any mutations of mutable default values will persist between invocations.** @@ -712,39 +712,39 @@ def add(*a): #### Legal argument combinations: ```python -def f(*, x, y, z): # f(x=1, y=2, z=3) -def f(x, *, y, z): # f(x=1, y=2, z=3) | f(1, y=2, z=3) -def f(x, y, *, z): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) +def f(*, x, y, z): ... # f(x=1, y=2, z=3) +def f(x, *, y, z): ... # f(x=1, y=2, z=3) | f(1, y=2, z=3) +def f(x, y, *, z): ... # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) ``` ```python -def f(*args): # f(1, 2, 3) -def f(x, *args): # f(1, 2, 3) -def f(*args, z): # f(1, 2, z=3) +def f(*args): ... # f(1, 2, 3) +def f(x, *args): ... # f(1, 2, 3) +def f(*args, z): ... # f(1, 2, z=3) ``` ```python -def f(**kwargs): # f(x=1, y=2, z=3) -def f(x, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) -def f(*, x, **kwargs): # f(x=1, y=2, z=3) +def f(**kwargs): ... # f(x=1, y=2, z=3) +def f(x, **kwargs): ... # f(x=1, y=2, z=3) | f(1, y=2, z=3) +def f(*, x, **kwargs): ... # f(x=1, y=2, z=3) ``` ```python -def f(*args, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3) -def f(x, *args, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3) -def f(*args, y, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) +def f(*args, **kwargs): ... # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3) +def f(x, *args, **kwargs): ... # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3) +def f(*args, y, **kwargs): ... # f(x=1, y=2, z=3) | f(1, y=2, z=3) ``` ### Other Uses ```python - = [* [, ...]] - = {* [, ...]} - = (*, [...]) - = {** [, ...]} + = [* [, ...]] # Or: list() [+ ...] + = (*, [...]) # Or: tuple() [+ ...] + = {* [, ...]} # Or: set() [| ...] + = {** [, ...]} # Or: dict(** [, ...]) ``` ```python -head, *body, tail = +head, *body, tail = # Also `head, *body = ` and `*body, tail = `. ``` @@ -752,16 +752,16 @@ Inline ------ ### Lambda ```python - = lambda: - = lambda , : + = lambda: # A single statement function. + = lambda , : # Also accepts default arguments. ``` ### Comprehensions ```python - = [i+1 for i in range(10)] # [1, 2, ..., 10] - = {i for i in range(10) if i > 5} # {6, 7, 8, 9} - = (i+5 for i in range(10)) # (5, 6, ..., 14) - = {i: i*2 for i in range(10)} # {0: 0, 1: 2, ..., 9: 18} + = [i+1 for i in range(10)] # Or: [1, 2, ..., 10] + = (i for i in range(10) if i > 5) # Or: iter([6, 7, 8, 9]) + = {i+5 for i in range(10)} # Or: {5, 6, ..., 14} + = {i: i*2 for i in range(10)} # Or: {0: 0, 1: 2, ..., 9: 18} ``` ```python @@ -771,9 +771,9 @@ Inline ### Map, Filter, Reduce ```python - = map(lambda x: x + 1, range(10)) # (1, 2, ..., 10) - = filter(lambda x: x > 5, range(10)) # (6, 7, 8, 9) - = reduce(lambda out, x: out + x, range(10)) # 45 + = map(lambda x: x + 1, range(10)) # Or: iter([1, 2, ..., 10]) + = filter(lambda x: x > 5, range(10)) # Or: iter([6, 7, 8, 9]) + = reduce(lambda out, x: out + x, range(10)) # Or: 45 ``` * **Reduce must be imported from the functools module.** @@ -1064,7 +1064,7 @@ from dataclasses import make_dataclass #### Rest of type annotations (CPython interpreter ignores them all): ```python -def func(: [= ]) -> : +def func(: [= ]) -> : ... : typing.List/Set/Iterable/Sequence/Optional[] : typing.Dict/Tuple/Union[, ...] ``` diff --git a/index.html b/index.html index 8c71ccd..da52fc7 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -589,15 +589,15 @@ to_exclusive = <range>.stop <float> = <TD> / <TD> # How many weeks/years there are in TD. Also //. -

#Arguments

Inside Function Call

<function>(<positional_args>)                  # f(0, 0)
-<function>(<keyword_args>)                     # f(x=0, y=0)
-<function>(<positional_args>, <keyword_args>)  # f(0, y=0)
+

#Arguments

Inside Function Call

func(<positional_args>)                           # func(1, 2)
+func(<keyword_args>)                              # func(x=1, y=2)
+func(<positional_args>, <keyword_args>)           # func(1, y=2)
 
-

Inside Function Definition

def f(<nondefault_args>):                      # def f(x, y):
-def f(<default_args>):                         # def f(x=0, y=0):
-def f(<nondefault_args>, <default_args>):      # def f(x, y=0):
+

Inside Function Definition

def func(<nondefault_args>): ...                  # def func(x, y): ...
+def func(<default_args>): ...                     # def func(x=0, y=0): ...
+def func(<nondefault_args>, <default_args>): ...  # def func(x, y=0): ...
 
    @@ -622,48 +622,48 @@ func(*args, **kwargs)
    >>> add(1, 2, 3)
     6
     
    -

    Legal argument combinations:

    def f(*, x, y, z):          # f(x=1, y=2, z=3)
    -def f(x, *, y, z):          # f(x=1, y=2, z=3) | f(1, y=2, z=3)
    -def f(x, y, *, z):          # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3)
    +

    Legal argument combinations:

    def f(*, x, y, z): ...          # f(x=1, y=2, z=3)
    +def f(x, *, y, z): ...          # f(x=1, y=2, z=3) | f(1, y=2, z=3)
    +def f(x, y, *, z): ...          # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3)
     
    -
    def f(*args):               # f(1, 2, 3)
    -def f(x, *args):            # f(1, 2, 3)
    -def f(*args, z):            # f(1, 2, z=3)
    +
    def f(*args): ...               # f(1, 2, 3)
    +def f(x, *args): ...            # f(1, 2, 3)
    +def f(*args, z): ...            # f(1, 2, z=3)
     
    -
    def f(**kwargs):            # f(x=1, y=2, z=3)
    -def f(x, **kwargs):         # f(x=1, y=2, z=3) | f(1, y=2, z=3)
    -def f(*, x, **kwargs):      # f(x=1, y=2, z=3)
    +
    def f(**kwargs): ...            # f(x=1, y=2, z=3)
    +def f(x, **kwargs): ...         # f(x=1, y=2, z=3) | f(1, y=2, z=3)
    +def f(*, x, **kwargs): ...      # f(x=1, y=2, z=3)
     
    -
    def f(*args, **kwargs):     # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
    -def f(x, *args, **kwargs):  # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
    -def f(*args, y, **kwargs):  # f(x=1, y=2, z=3) | f(1, y=2, z=3)
    +
    def f(*args, **kwargs): ...     # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
    +def f(x, *args, **kwargs): ...  # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
    +def f(*args, y, **kwargs): ...  # f(x=1, y=2, z=3) | f(1, y=2, z=3)
     
    -

    Other Uses

    <list>  = [*<collection> [, ...]]
    -<set>   = {*<collection> [, ...]}
    -<tuple> = (*<collection>, [...])
    -<dict>  = {**<dict> [, ...]}
    +

    Other Uses

    <list>  = [*<coll.> [, ...]]    # Or: list(<collection>) [+ ...]
    +<tuple> = (*<coll.>, [...])     # Or: tuple(<collection>) [+ ...]
    +<set>   = {*<coll.> [, ...]}    # Or: set(<collection>) [| ...]
    +<dict>  = {**<dict> [, ...]}    # Or: dict(**<dict> [, ...])
     
    -
    head, *body, tail = <collection>
    +
    head, *body, tail = <coll.>     # Also `head, *body = <coll.>` and `*body, tail = <coll.>`.
     
    -

    #Inline

    Lambda

    <func> = lambda: <return_value>
    -<func> = lambda <arg_1>, <arg_2>: <return_value>
    +

    #Inline

    Lambda

    <func> = lambda: <return_value>                           # A single statement function.
    +<func> = lambda <arg_1>, <arg_2>: <return_value>          # Also accepts default arguments.
     
    -

    Comprehensions

    <list> = [i+1 for i in range(10)]                         # [1, 2, ..., 10]
    -<set>  = {i for i in range(10) if i > 5}                  # {6, 7, 8, 9}
    -<iter> = (i+5 for i in range(10))                         # (5, 6, ..., 14)
    -<dict> = {i: i*2 for i in range(10)}                      # {0: 0, 1: 2, ..., 9: 18}
    +

    Comprehensions

    <list> = [i+1 for i in range(10)]                         # Or: [1, 2, ..., 10]
    +<iter> = (i for i in range(10) if i > 5)                  # Or: iter([6, 7, 8, 9])
    +<set>  = {i+5 for i in range(10)}                         # Or: {5, 6, ..., 14}
    +<dict> = {i: i*2 for i in range(10)}                      # Or: {0: 0, 1: 2, ..., 9: 18}
     
    >>> [l+r for l in 'abc' for r in 'abc']
     ['aa', 'ab', 'ac', ..., 'cc']
     
    -

    Map, Filter, Reduce

    <iter> = map(lambda x: x + 1, range(10))                  # (1, 2, ..., 10)
    -<iter> = filter(lambda x: x > 5, range(10))               # (6, 7, 8, 9)
    -<obj>  = reduce(lambda out, x: out + x, range(10))        # 45
    +

    Map, Filter, Reduce

    <iter> = map(lambda x: x + 1, range(10))                  # Or: iter([1, 2, ..., 10])
    +<iter> = filter(lambda x: x > 5, range(10))               # Or: iter([6, 7, 8, 9])
    +<obj>  = reduce(lambda out, x: out + x, range(10))        # Or: 45
     
      @@ -903,7 +903,7 @@ Z = dataclasses.make_dataclass('Z', ['<class_name>', <coll_of_tuples>) <tuple> = ('<attr_name>', <type> [, <default_value>])
    -

    Rest of type annotations (CPython interpreter ignores them all):

    def func(<arg_name>: <type> [= <obj>]) -> <type>:
    +

    Rest of type annotations (CPython interpreter ignores them all):

    def func(<arg_name>: <type> [= <obj>]) -> <type>: ...
     <var_name>: typing.List/Set/Iterable/Sequence/Optional[<type>]
     <var_name>: typing.Dict/Tuple/Union[<type>, ...]
     
    @@ -2370,7 +2370,8 @@ samples_f = (add_noise(f) for f 'test.wav', samples_f)
    -

    Plays a WAV file:

    # $ pip3 install simpleaudio
    +

    Plays a WAV file:

    # $ sudo apt install libasound2-dev
    +# $ pip3 install simpleaudio
     from simpleaudio import play_buffer
     with wave.open('test.wav', 'rb') as file:
         p = file.getparams()
    @@ -2378,11 +2379,10 @@ write_to_wav_file('test.wav', samples_f)
         play_buffer(frames, p.nchannels, p.sampwidth, p.framerate)
     
    -

    Text to Speech

    # $ pip3 install pyttsx3
    +

    Text to Speech

    # $ sudo apt install espeak ffmpeg libespeak1
    +# $ pip3 install pyttsx3
     import pyttsx3
    -engine = pyttsx3.init()
    -engine.say('Sally sells seashells by the seashore.')
    -engine.runAndWait()
    +pyttsx3.speak(<str>)                            # Reads the string while blocking.
     

    #Synthesizer

    Plays Popcorn by Gershon Kingsley:

    # $ pip3 install simpleaudio
    @@ -2902,7 +2902,7 @@ $ pyinstaller script.py --add-data '<path>:.'