Data types in Python, integer, float and boolean

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/meiguanxi7878/article/details/102732975

What is a data type? Storing data in the end to which variable is an integer or a character or decimal etc, although Python does not need to define a variable declared in advance what type of data the time, but when in use or the data type of the points.

Python has five standard data types: digital (numeric), strings, tuples, lists, dictionaries

What is the value type?

Numeric types include: integer, float, boolean

First, the integer:

1) Integer (Int) - often referred to is an integer or an integer, is positive or negative integer, with no decimal.

Python3 is no limit to the size of the integer, can use as Long type, so Python3 no Python2 of Long.

Such as: num01 02 03 04 are integers, num05 is float, decimal only have scientific notation

Integer

2) How to view variables take up much space?

Such as:

**import ** sys

Print ( "num01 space occupied" , sys.getsizeof (num01))

Print ( "num02 space occupied" , sys.getsizeof (num02))

storage

3) Integer common methods:

Function returns a value (to be described)

** abs (x) ** Returns the absolute value, such as abs (-10) returns 10

** math.fabs (x) ** Returns the absolute value, as math.fabs (-10) returned 10.0

** math.sqrt (x) ** returns the square root of the number x.

Math.pow ** (X, Y) X value calculation y. x power of y

** max (x1, x2, ...) ** returned to the maximum value of the given parameter

** min (x1, x2, ...) ** returned to the minimum value of the given parameter

Such as:

Integer common method

Interested in Python or are studying a small partner, you can join us to learn Python buckle qun: 784758214, look at how seniors are learning! From basic web development python script to, reptiles, django, data mining and other projects to combat zero-based data are finishing. Given to every little python partner! Every day, Daniel explain the timing Python technology, to share some of the ways to learn and need to pay attention to small details, click on Join us python learner gathering

Second, the float

The **: ** float accuracy of 17, over 17 represented in scientific notation

Python中的数据类型,整型,浮点型和布尔类型

Float

1) float inside round , retains the number after the decimal point position, often used

Such as:

Python中的数据类型,整型,浮点型和布尔类型

round use

Instead of the standard rounding, there is a rule:

round () If only one number as an argument, when not specified number of digits, returns an integer, and is the nearest integer (similar rounding on this point). However, when there is .5, are the same distance from both sides, round () takes an even closer, which is why the round (2.5) = 2. When the specified number of decimal places of choice when the usage rules are generally rounded, but faced with this situation .5, if you choose the number of digits is odd trees before, directly discarded, the even if the choice up

2) floating-point inside the ceil

ceil use

Ceil Returns the number of the integers, positive and negative numbers differently

3) floor Returns the integer number of homes

Rounded integer

4) modf returns the integer part of X and fractional part, part of the two values ​​meet the same as X, an integer part expressed in floating-point

modf keyword

Return, but the value is not very accurate

Third, Boolean: False True can participate in math

Boolean

All non-integer 0 is true, 0 is False

python data types

Guess you like

Origin blog.csdn.net/meiguanxi7878/article/details/102732975