LAMBDA EXPRESSIONS
Listing 1.12 displays the contents of Lambda1.py that illustrates how to create a simple lambda function in Python.
LISTING 1.12: Lambda1.py
add = lambda x, y: x + y
x1 = add(5,7)
x2 = add('Hello', 'Python')
print(x1)
print(x2)
Listing 1.12 defines the lambda expression add that accepts two input parameters and then returns their sum (for numbers) or their concatenation (for strings).
The output from Listing 1.12 is here:
12 HelloPython
The next portion of this chapter discusses Python collections, such as lists (or arrays), sets, tuples, and dictionaries. You will see many short code blocks that will help you rapidly learn how to work with these data structures in Python. After you have finished reading this chapter, you will be in a better position to create more complex Python modules using one or more of these data structures.