Python naming convention for variables that are functions

Does Python have a naming convention for variables that are functions? I could not see anything specific for this in PEP-8 (except for variable names).

Since functions are first-class objects in Python, _fndoes it use a suffix or something similar, a recognized convention?

EDIT : updated with a more realistic example

Example:

def foo_a():
    print 'a'

def foo_b():
    print 'b'

funcs = {'a': foo_a, 'b': foo_b}

# dynamically select function based on some key
key = 'a'
foo_fn = funcs[key]
+4
source share
2 answers

Does Python have a naming convention for variables that are functions?

No, it’s not, functions are first class objects in Python. Pass the name of the function as you will gain access to it for calling.

For instance:

def foo():
    pass

foo() # calling

another_function(foo) # passing foo

- . , , , , . :

def do_nothing():
    pass

EDIT: , _fn , :

def foo_a():
    print 'a'

def foo_b():
    print 'b'

funcs = {'a': foo_a, 'b': foo_b}

# dynamically select function based on some key
key = 'a'
foo_fn = funcs[key]

foo_fn() # calling
another_function(foo_fn) # passing
+4

- , Python . callable - , str, list dict. , , , , callable.

0

Source: https://habr.com/ru/post/1598918/


All Articles