math.trunc_带有Python示例的math.trunc()方法
math.trunc
Python math.trunc()方法 (Python math.trunc() method)
math.trunc() method is a library method of math module, it is used to get the truncated integer value of a number, it accepts a number (either an integer or a float) and returns the real value truncated to an integral.
math.trunc()方法是math模塊的庫方法,用于獲取數(shù)字的截斷整數(shù)值,它接受數(shù)字(整數(shù)或浮點數(shù))并返回被截斷為整數(shù)的實數(shù)值。
Note: If anything is passed except the number, the method returns a type error, if we pass a string – it will return "TypeError: type str doesn't define __trunc__ method"
注意:如果傳遞了除數(shù)字以外的任何內(nèi)容,則該方法將返回類型錯誤,如果我們傳遞一個字符串,則將返回“ TypeError:類型str未定義__trunc__方法”
Syntax of math.trunc() method:
math.trunc()方法的語法:
math.trunc(n)Parameter(s): n – an integer or a float number.
參數(shù): n-整數(shù)或浮點數(shù)。
Return value: int – it returns an integer value that is the integral part of the number n.
返回值: int –它返回整數(shù)值,該整數(shù)值是數(shù)字n的整數(shù)部分。
Example:
例:
Input:a = 10.23# function callprint(math.trunc(a))Output:10Python代碼演示math.trunc()方法的示例 (Python code to demonstrate example of math.trunc() method)
# Python code demonstrate example of # math.trunc() method# importing math module import math# numbers a = 10 b = 10.23 c = -10 d = -10.67 e = 10.67# printing the fractional and integer part # of the numbers by using math.trunc()print("trunc(a): ", math.trunc(a)) print("trunc(b): ", math.trunc(b)) print("trunc(c): ", math.trunc(c)) print("trunc(d): ", math.trunc(d)) print("trunc(e): ", math.trunc(e))Output
輸出量
trunc(a): 10 trunc(b): 10 trunc(c): -10 trunc(d): -10 trunc(e): 10Recommended posts
推薦的帖子
math.factorial() method with example in Python
帶有Python示例的math.factorial()方法
math.isfinite() method with example in Python
帶有Python示例的math.isfinite()方法
math.isinf() method with example in Python
帶有Python示例的math.isinf()方法
math.remainder() method with example in Python
帶有Python示例的math.remainder()方法
math.ceil() method with example in Python
Python中帶有示例的math.ceil()方法
math.floor() method with example in Python
帶有Python示例的math.floor()方法
math.exp() method with example in Python
帶有Python示例的math.exp()方法
math.fabs() method with example in Python
帶有Python示例的math.fabs()方法
math.fmod() method with example in Python
帶有Python示例的math.fmod()方法
math.modf() method with example in Python
帶有Python示例的math.modf()方法
math.fsum() method with example in Python
帶有Python示例的math.fsum()方法
abs() vs fabs() methods in Python
Python中的abs()vs fabs()方法
math.gcd() method with example in Python
帶有Python示例的math.gcd()方法
math.pow() method with example in Python
帶有Python示例的math.pow()方法
math.sqrt() method with example in Python
帶有Python示例的math.sqrt()方法
翻譯自: https://www.includehelp.com/python/math-trunc-method-with-example.aspx
math.trunc
總結(jié)
以上是生活随笔為你收集整理的math.trunc_带有Python示例的math.trunc()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 优先级调度算法动态优先级_与优先级调度有
- 下一篇: python 获取当前目录_如何在Pyt