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
    • SQL FAQ’s

Python modf

by suresh

The Python modf function is one of the Python Mathematical Functions used to divide the given value into two arguments. Fractional Part as the first argument and integer value as the second argument of Python modf function. In this section, we discuss how to use modf function in Python Programming language with example.

The syntax of the modf Function in Python Programming Language is

math.modf(Number);

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

  • If the number argument is a positive or negative number, the modf function returns the first argument as Zero.
  • If the number argument is positive or negative decimal, modf function returns the first argument as decimal values, and the second argument is an integer value.
  • And if it is not a number, modf function returns TypeError.

For example, math.modf(2.45) returns 0.45 as the first argument and 2.00 as the second argument. Final output = (0.45, 2.00)

Python modf Function Example

The Python modf function divides the given value into two arguments. The Fractional Part as first and integer value as the second Python argument. In this modf example, We are going to return the same for different data types and display the output.

# Python modf Function

import math

Tup = (10.98, 20.26, -30.05, -40.95 , 50.85) # Tuple Declaration
Lis = [-10.98, 32.65, -39.29, -42.15 , 39.97] # List Declaration

print('MODF() Function on Positive Number = ', math.modf(10))
print('MODF() Function on Negative Decimal = ', math.modf(-15))

print('MODF() Function on Positive Decimal = ', math.modf(10.9))
print('MODF() Function on Negative Decimal = ', math.modf(-15.487))

print('MODF() Function on Tuple Item = ', math.modf(Tup[2]))
print('MODF() Function on Tuple Item = ', math.modf(Tup[4]))
print('MODF() Function on List Item = ', math.modf(Lis[2]))
print('MODF() Function on List Item = ', math.modf(Lis[4]))

print('MODF() Function on Multiple Number = ', math.modf(10 + 20 - 40.6578))

print('MODF() Function on String Value = ', math.modf('2.95'))

OUTPUT

Python MODF Function

ANALYSIS

  1. In the first two statements, We used the modf Function directly on both the Positive and Negative Numbers.
  2. Next two statements, We used the Python modf Function directly on both the Positive decimals and negative decimals.
  3. Next four statements, We used the modf Math function on Tuple and List items. If you observe the above screenshot, modf function is working perfectly on them.
  4. Here, we tried modf Function directly on multiple values
  5. Last, We tried this Python Function on the String value, and it returns TypeError 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
  • 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