What is a Lambda form? Explain about assert statement?

Answer Posted / chaitanya

The lambda form:

Using lambda keyword tiny anonymous functions can be created.

It is a very powerful feature of Python which declares a one-line unknown small function on the fly. The lambda is used to create new function objects and then return them at runtime.

The general format for lambda form is:

lambda parameter(s): expression using the parameter(s)

For instance k is lambda function-

>>> k= lambda y: y + y

>>> k(30)

60

>>> k(40)

80

The assert statement:

The build-in assert statement of python introduced in version 1.5 is used to assert that something is true.

Programmers often place assertions at the beginning of a function to check for valid input, and after function call to check for valid output. Assert statement can be removed after testing of program is over.

If assert evaluates to be false, an AssertionError exception is raised. AssertionError exceptions can be handled with the try-except statement.

The general syntax for assert statement is:

assert Expression[, Arguments]

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to create a class and make an object of the class in python?

584


Is python better than matlab?

536


What are the components of python memory manager?

569


What is cgi in python?

612


What are the 4 data types in python?

544






What is the purpose of "self" in python

655


How to find methods or attributes of an object?

580


How can you organize your code to make it easier to change the base class?

595


What are the other languages that support strongly for regular expressions?

652


Is there a switch..case statement in python?

588


What does head () do in python?

564


Can we use angularjs with python?

540


Which are the file related libraries/modules in python?

575


What is python main function and write one good example?

596


What are the 3 types of loops?

558