Introduction to the modf () method in Python

Source: Internet
Author: User
This article describes how to use the modf () method to get started with Python. It is a basic knowledge of Python learning. For more information, see modf () returns the integer decimal part of the tuples x of two items. These two tuples have the same x symbol. Returns the integer part of a floating point number.
Syntax

The syntax of the modf () method is as follows:

import mathmath.modf( x )

Note: This function cannot be directly accessed. Therefore, we need to import the math module and then use the static object of math to call this function.
Parameters

  • X -- this is a numeric expression.

Return Value

This method returns the integer decimal part of x in the tuples of the two items. Has the same x symbol. Returns a floating point number.
Example

The following example shows how to use the modf () method.

#!/usr/bin/pythonimport math  # This will import math moduleprint "math.modf(100.12) : ", math.modf(100.12)print "math.modf(100.72) : ", math.modf(100.72)print "math.modf(119L) : ", math.modf(119L)print "math.modf(math.pi) : ", math.modf(math.pi)

When we run the above program, it will produce the following results:

math.modf(100.12) : (0.12000000000000455, 100.0)math.modf(100.72) : (0.71999999999999886, 100.0)math.modf(119L) :  (0.0, 119.0)math.modf(math.pi) : (0.14159265358979312, 3.0)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.