Enrollments started for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 5 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
Functions, like the one you defined in the last exercise perform an action but don't return a value. They are called void functions. You almost always want to do something with the result. For example, you might assign it to a variable or use it as part of an expression:
def void_function(number):
num = number
print(num)
Void functions might display something on the screen or have some other effect, but they don't have a return value. If you try to assign the result to a variable, you get a special value called None
.
The value None
is not the same as the string "None". It is a special value that has its own type:
print(type(None))
It returns <class 'NoneType'>
Some of the functions, such as the math functions, return certain results.
def multiply(a, b):
multiplication = a * b
return multiplication
multiplication_numbers = multiply(1,2)
This function when called returns the result of the multiplication of numbers a
and b
, i.e 2
and stores it in the variable multiplication_numbers
.
new_function
that takes an argument num
and returns its multiplication with π.void_function
which takes two arguments num1
and num2
which makes the call to new_function
with an argument as num1
raised to the power of num2
. void_function
print the value returned by the call.void_function
with arguments as 4.6
and 7.3
.Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...