Search notes:

Python standard library: functools.partial

partial(func) creates a partial object from the function func. Such a partial object has already pre-bound some of the function's parameters to arguments. These pre-bound values will then be used when the function will be called with the partial object.
from functools import partial

def F(p1 = 'one', p2 = 'two', p3 = 'three', p4='four', p5='five'):
    print(f'p1: {p1}')
    print(f'p2: {p2}')
    print(f'p3: {p3}')
    print(f'p4: {p4}')
    print(f'p5: {p5}')


f = partial(F, 'A', 'B', p4 = 'Y', p5 = 'Z')

assert f.func is F

print (f.args    )
#
#   ('A', 'B')

print (f.keywords)
#
#   {'p4': 'Y', 'p5': 'Z'}


f('C')
#
#  p1: A
#  p2: B
#  p3: C
#  p4: Y
#  p5: Z

f(p4 = 'y')
#
#  p1: A
#  p2: B
#  p3: three
#  p4: y
#  p5: Z
Github repository about-Python, path: /standard-library/functools/partial/demo.py

See also

functools

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204091, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/standard-library/functools/partial(78): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78