程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python number

編輯:Python

del Delete object reference

del var1,var2 ....

  • 1.


Python Three different numerical types are supported :

1、 integer (int) It is often called an integer or integer , It's a positive or negative integer , Without decimal point

2、 floating-point (float) It usually consists of an integer part plus a decimal point , Floating point types can also be represented by scientific and technical methods 2.5e

3、 The plural (complex) The plural consists of the real part and the imaginary part , You can use a+bj Express Also available complex(a , b) Express , The real part of a complex number a Deficiency part of harmony b It's all floating point


Data type conversion

Sometimes you need some reason to convert the data type to output , Just use the required data type as the function name

1、int(x)         take x Convert to an integer

2、float(x)     take x Converts to a floating point number

3、complex(x)      take x To a complex number , The real part is x, The imaginary part is 0

4、complex(x,y)     take x To a complex number , The real part is x, The imaginary part is y

Example : Convert floating-point number to integer output , But the data type has not changed


Python Number operation

You can directly operate various expressions in the command-line interpreter

//  Divide and conquer    What you get is not necessarily a number of integer type , It has something to do with the data type of denominator .

Equal sign = Used to assign values to variables , After assignment, it will not be echoed to the page

Variables must be defined before they are used , Otherwise, it will report a mistake

Different types of numeric blending operations convert integers to other data types

In interactive mode , Finally, the output expression result is assigned to the variable _

for example :

round(str,length) Retain several decimal places after intercepting the string


Mathematical functions

abs() Get absolute value

abs(-10)

ceil() Returns an upinteger of a number , namely 3.1 return 4

This function needs to introduce math modular , Otherwise, you will be prompted that this function is not found and not defined

import math

math.ceil(4.2)

fabs() Returns the absolute value of the number ( Floating point numbers )

This function also needs to introduce math modular

a = 10

import math
math.fabs(a)
  • 1.
  • 2.
  • 3.

floor() Returns the rounded value of a number , Such as :math.floor(4.2) return 4

math.floor(4.9)
  • 1.
  • 2.


max()、min() Returns the maximum in the sequence 、 minimum value

min(50,24,36,100,94,241,2166,1)

max(13,51,1563,142,240,74,5000)
  • 1.
  • 2.

pow(x,y) return x**y After the value of

math.pow(2,5)

round(str,length) Retain several decimal places after intercepting the string

Without parameters, it is rounded

Plus the parameter is to keep several decimal places


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved