In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "conversion of Python digital types", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python digital type conversion" bar!
The Python numeric data type is used to store values.
The data type is not allowed to be changed, which means that if you change the value of the numeric data type, the memory space will be reallocated.
The following example creates a digital object when a variable is assigned:
Var1 = 1
Var2 = 10
You can also use the de statement to delete some numeric object references.
The syntax of the del statement is:
Del var1 [, var2 [, var3 [...., varN]
You can delete single or multiple objects by using the de statement, for example:
Del var
Del var_a, var_b
Python supports four different numeric types:
Integer (Int)-often referred to as an integer or integer, is a positive or negative integer without a decimal point.
Long integer (long integers)-an infinitely large integer that ends with an uppercase or lowercase L.
Floating point type (floating point real values)-A floating point type consists of an integer part and a fractional part, and can also be represented by scientific counting (2.5e2 = 2.5x 102250)
Plural ((complex numbers))-the imaginary part of the plural ends with the letter J or j. Such as: 2cm 3i
Int
Long
Float
Complex
ten
51924361L
0.0
3.14j
one hundred
-0x19323L
15.20
45.j
-786
0122L
-21.9
9.322e-36j
080
0xDEFABCECBDAECBFBAEl
32.3+e18
.876j
-0490
535633629843L
-90.
-.65450J
-0x260
-052318172735L
-3.254e+89 trillion
3e+26J
0x69
-4721885298529L
70.2-E12
4.53e-7j
Long integers can also use lowercase "L", but it is recommended that you use uppercase "L" to avoid confusion with the number "1". Python uses "L" to display long integers.
Python also supports complex numbers, which are made up of real and imaginary parts, which can be represented by a + bj or complex (aforce b). Both the real part an and the imaginary part b of the complex number are floating point.
Python digital type conversion
Int (x [, base]) converts x to an integer
Long (x [, base]) converts x to a long integer
Float (x) converts x to a floating point number
Complex (real [, imag]) creates a plural
Str (x) converts object x to a string
Repr (x) converts object x to an expression string
Eval (str) is used to evaluate a valid Python expression in a string and returns an object
Tuple (s) converts sequence s into a tuple
List (s) converts sequence s into a list
Chr (x) converts an integer to a character
Unichr (x) converts an integer to a Unicode character
Ord (x) converts a character to its integer value
Hex (x) converts an integer to a hexadecimal string
Oct (x) converts an integer to an octal string
Python mathematical function
Function
Return value (description)
Abs (x)
Returns the absolute value of a number, such as abs (- 10) returns 10
Ceil (x)
Returns the upside integer of a number, such as math.ceil (4. 1) returns 5
Cmp (x, y)
If x
< y 返回 -1, 如果 x == y 返回 0, 如果 x >Y returns 1
Exp (x)
Returns the x power of e (ex), for example, math.exp (1) returns 2.718281828459045
Fabs (x)
Returns the absolute value of a number, such as math.fabs (- 10) returns 10.0
Floor (x)
Returns the rounded integer of a number, such as math.floor (4.9) returns 4
Log (x)
For example, math.log (math.e) returns 1.0 Magi math.log (100 Jing 10) returns 2.0
Log10 (x)
Returns the logarithm of x with a base of 10, such as math.log10 (100) returns 2.0
Max (x1, x2...)
Returns the maximum value of a given parameter, which can be a sequence.
Min (x1, x2...)
Returns the minimum value of a given parameter, which can be a sequence.
Modf (x)
Returns the integer part and the decimal part of x, the numerical symbols of both parts are the same as x, and the integer part is represented as a floating point.
Pow (x, y)
The value after the xroomy operation.
Round (x [, n])
Returns the rounded value of the floating point number x. If n is given, it represents the number of digits rounded to the decimal point.
Sqrt (x)
Returns the square root of the number x. The number can be negative and the return type is real. For example, math.sqrt (4) returns 2zero j.
Python random number function
Random numbers can be used in mathematics, games, security and other fields, and are often embedded in the algorithm to improve the efficiency of the algorithm and improve the security of the program.
Python contains the following common random number functions:
Function
Description
Choice (seq)
Pick an element randomly from the elements of the sequence, such as random.choice (range (10)), and randomly pick an integer from 0 to 9.
Randrange ([start,] stop [, step])
Gets a random number from a set that is incremented by the specified cardinality within the specified range, with a default cardinality of 1
Random ()
The next real number is randomly generated, which is in the range of [0mem1).
Seed ([x])
Change the seed seed of the random number generator. If you don't know how it works, you don't have to set seed,Python to help you choose seed.
Shuffle (lst)
Sort all the elements of the sequence randomly
Uniform (x, y)
The next real number is randomly generated, which is in the range of [xmemy].
Python trigonometric function
Python includes the following trigonometric functions:
Function
Description
Acos (x)
Returns the inverse cosine arc value of x.
Asin (x)
Returns the arcsine arc value of x.
Atan (x)
Returns the arc value of the arc of x.
Atan2 (y, x)
Returns the arc tangent of the given X and Y coordinate values.
Cos (x)
Returns the cosine of the radians of x.
Hypot (x, y)
Returns the Euclidean norm sqrt (x\ x + y\ y).
Sin (x)
The sine of the returned x radians.
Tan (x)
Returns the tangent of x radians.
Degrees (x)
Convert radians to angles, such as math.degrees (math.tan (1.0)), and return 30.0
Radians (x)
Convert angles to radians
Python mathematical constant
Constant
Description
Pi
Mathematical constant pi (pi, generally expressed as pi)
E
The mathematical constant e is a natural constant (natural constant).
Thank you for your reading, the above is the content of "the conversion of Python digital types". After the study of this article, I believe you have a deeper understanding of the conversion of Python digital types, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.