» » Python range function recursive

# Python range function recursive

Recursion:
• The process of calling a function by itself is called recursion and the function which calls itself is called recursive function.
• Recursion is used to solve various mathematical problems by dividing it into smaller problems. This method of solving a problem is called Divide and Conquer. In programming, it is used to divide complex problem into simpler ones and solving them individually.
• In order to prevent infinite recursive call,we need to define proper exit condition in a recursive function.

• Python program to show recursive function

• n=4
• def  a(n):
•  if n==0:
•     return 0
•  else:
• print(n)
• Return a(n-1)

• Python range for float numbers
• Limitation of  python’s range() function
• The main limitation of Python’s range() is it works only with integers. Python range() doesn’t support the float type i.e., we cannot use floating-point or non-integer number in any of its argument.
• For example,  Let’s see the following source code
• for num in range(0, 5.5, 0.1):
•   print (num)
• If you try to execute above code Python will raise a TypeError: ‘float’ object cannot be interpreted as an integer.

• Now, Let see how to generate the range for float numbers? There are various ways to do this Let see one by one with the examples.
• Use numpy’s arange() function to generate the range for float numbers in Python.
• We can use the numpy module of Python programming language to get the range of floating-point numbers.

• NumPy library has various numeric functions and mathematical functions to operate on multi-dimensional arrays and matrices.
• NumPy has the arange() function to get the range of a floating-point number.
• arange() function has the same syntax and functionality as python range() function.
• Additionally, it also supports floating-point numbers in any of its argument.
• i.e., we can pass float number in the start, stop and step arguments.

Syntax of numpy’s arange() function: –
• arange (start, stop, step)
• Let demonstrate the use with the following example.

#### Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«