Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Python gamma

by suresh

The Python gamma function is a special Python Math function used to calculate the Gamma value of the given argument. In this section, we discuss how to use gamma function in Python Programming language with example. Before we step into the gamma function syntax, let us see the mathematical formula behind the gamma function:

Math.gamma(Number) = (Number – 1)!

It means the Python gamma function subtracts one from the Given number, and then it finds the factorial. For example, Math.gamma(6) = 5!

The syntax of the gamma Function in Python Programming Language is

math.gamma(Number);

Number: It can be a number or a valid numerical expression.

  • If the number argument is a positive integer, positive or negative decimals, then gamma function returns the output.
  • If the number argument is Negative integer, gamma function returns ValueError.
  • And if it is not a number, the gamma function returns TypeError.

Python gamma Function Example

The Python gamma function calculates the Gamma value of the given argument. In this example, we use the gamma function to find the gamma value of different data types and display the output.

# Python gamma Function

import math

Tup = (1, 2, 8, 4 , 5) # Tuple Declaration
Lis = [8, 3, 9, 5 , 7] # List Declaration

print('Gamma() Function on Positive Number = %d' %math.gamma(2))
print('Gamma() Function on Positive Number = %d' %math.gamma(6))

print('Gamma() Function on Positive Decimal = %.2f' %math.gamma(4.5))
print('Gamma() Function on Negative Decimal = %.2f' %math.gamma(-2.78))

print('Gamma() Function on Tuple Item = %d' %math.gamma(Tup[2]))
print('Gamma() Function on List Item = %d' %math.gamma(Lis[2]))

print('Gamma() Function on Multiple Number = %d' %math.gamma(10 + 20 - 25))

print('Gamma() Function on String Value = ', math.gamma('3'))

OUTPUT

Python GAMMA Function

ANALYSIS

  1. First, we declared Python List and Tuple with some random values.
  2. Within the first two statements, We passed the Positive integers as the gamma Function argument. From the above screenshot, see that the gamma Function is returning output.
  3. Within the next two statements, we passed both the Positive and negative decimals as the gamma Function argument. As we said before, the gamma Function is returning the output.
  4. Next two statements, we used the Tuple and List items as the gamma Math functions argument. If you observe the above screenshot, the gamma function is working correctly on them.
  5. Next statement, We assigned multiple values as the argument, and the gamma Function worked without any issue.
  6. We tried gamma Function on the String value. As we said earlier, it returns TypeError as output
  7. Within the Python IDE, we passed the negative integer as an argument for gamma Function. As you can, it is returning ValueError as output.

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python Numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python Numpy concatenate
  • Python Numpy Array shape
  • Python pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python Substring
  • Python Programming Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy