Functions

Parameter Passing in Python

In the previous article, we have explored variable length arguments, now we will look at Parameter Passing in Python. When we pass a parameter to a function, how is it passed? Does it contain the same reference to a variable or a different variable, if we make any changes to this variable is it reflected …

Read more

How Functions Work in Python

In the previous article, we discussed the applications/advantages of using Functions in Python, now we will examine how functions work in Python. Before we delve further let us look at an example program. What would the output of the above code look like? Analyzing How Functions Work in Python The program from earlier would result …

Read more

Default Arguments in Python

In the previous article we saw the internal logic of Python functions and how they work. Now we will take a look at the Default Arguments in Python. Default arguments exist when the functions do not require values to be passed to them or the function accepts certain values even in the absence of user-given …

Read more

Find First Digit of a Number Python program

In the previous article, we explored Global Variables in Python, now we will look at how we can obtain the first digit of any given number. We have also seen how we can obtain the last digit of a number in an older different article. For example, if the input values are: 7549: It should …

Read more

Functions in Python

In the previous article, we saw how we could optimize code for two different problems. There is another way in which we can increase the effectiveness of code, that is true the use of in-built functions or user-defined rather than the use and repeat of long lines of code. So in this article, we will …

Read more

Prime Factorization in Python

In the previous article we looked at how we can obtain the first digit of any given number, now we will look at how we can achieve prime factorization in Python. We are given a number n, we need to find prime factorization of this number. We need to consider all the divisors of the …

Read more

Returning multiple Variables in Python

In the previous article saw how parameters are passed and handled in Python, now we will look at how we can return multiple variables in Python. Here is an example program that returns two values: When we call the function we receive the two values from add_multiply, later the program prints out the value of …

Read more

Global Variables in Python

In the previous article we looked at how we can return multiple variables in Python. Now let us discuss about Global Variables in Python, Global variables are the variables declared outside of functions and classes and that are accessible throughout the entire program. Here in this article we will mainly look at the use of …

Read more

Variable Length Arguments in Python

In the previous article we have discussed keyword arguments, now we will look at another type of argument that can be provided to functions: Variable length arguments. Many times we want a functionality to be implemented for various different inputs. If we pass two, then we want sum of two variables. We want a sum …

Read more

Applications of Functions in Python

In the previous article we had a look at the basics of Functions, now let us look at the various areas within a program’s code or script that a Function would come in handy. Functions are an essential part of most programming languages. Functions are reusable pieces of code that can be called using a …

Read more