Introduction to the modf () method in Python

Source: Internet
Author: User

Introduction to the modf () method in Python

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

 

 

The modf () method 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:

?

1

2

3

Import math

 

Math. 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.

?

1

2

3

4

5

6

7

#! /Usr/bin/python

Import math # This will import math module

 

Print "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:

?

1

2

3

4

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.