In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what is the base and data type of Python. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
First, base 1. What is base system?
Binary, or carry counting system, is an artificially defined counting method with carry (there are counting methods without carry, such as the original knot counting method, the "positive" word counting method commonly used in counting votes, and similar tally mark counting). For any system-X system, it means that the number in each position is calculated by one bit per X. Decimal is one for every decimal, hexadecimal is one for hexadecimal, binary is one for binary, and so on, x is carry for x. (from Baidu)
According to the popular explanation, the so-called base is a method of counting, and the number of base is to enter a bit to the high position when it is satisfied.
two。 Binary conversion.
In Python, you can convert binary to decimal through the built-in function int (); the int () function can convert a specified numeric string or decimal number to an integer.
Syntax:
Int (object,base)
Return value: returns integer data.
Convert binary numbers to decimal numbers
Test = ['111011011111111,' 0b110'] for number in test: print (int (number, 2))
Running result:
Converts octal numbers to decimal numbers.
Test = ['- 1537202, '125'] for number in test: print (int (number, 8))
Running result:
Second, numerical type 1. Boolean type
Boolean is actually a subtype of an integer. Boolean data has only two values: True and False, which correspond to 1 and 0 of the integer, respectively.
Every Python object is born with a Boolean value (True or False), which can be used in Boolean testing (such as in if, while).
The Boolean values of the following objects are all False:
An instance of a user-defined class that defines methods nonzero () or len () that return 0 or False.
All objects except the above have a Boolean value of True.
# 1. Boolean value > bool (None) False > bool (False), bool (0), bool (0L), bool (0.0), bool (0.01j) (False, False) > > bool ('), bool ([]), bool (()), bool ({}) (False, False) # 2. In the numerical operation, the Boolean values True and False correspond to 1 and 0 > > int (True) and int (2) of the integer, respectively.
< 1) (1, 0) >> > False + 100100 # output result > True + 100101 # output result 2. Integer type
Integer is equivalent to signed long integer (long) in C language, which is consistent with the maximum integer of the system (for example, 32-bit on 32-bit machines and 64-bit on 64-bit machines), and the range of representations is limited. There are three ways to represent integer literals: decimal (commonly used), binary (starting with "0b"), octal (starting with the number "0"), and hexadecimal (starting with "0x" or "0X").
> a = 0b10100 > type (a) int # output result > > a 20 # output result > bin (20), oct (20), hex (20) ('0b10100 output,' 024 #, '0x14') # output result 3. Long integer type
A long integer is a superset of integers that can represent infinite integers. The long integer literal value is followed by the letter "L" or "l" (using uppercase "L").
> a = 999 * * 8 # integer is automatically converted to long integer > a 8920457944069944027201L > type (a) long4. Floating point type
Floating point type is similar to double precision floating point type (double) in C. Floating-point literals can be expressed in decimal or scientific counting, in which e or E stands for 10 + (which can be omitted) or-represents the positive or negative of the index.
> type (1) int # output result > type (1) float # output result > 1 + 1.02.0 # output result > a = 1e-2 > a # output result > > type (a) float # output result > pi = 3.1415926 > round (pi) 3.0 # output result > round (pi, 4) 3.1416 # output result 5. Complex number
The concept of complex number is exactly the same as that in mathematics. The plural in Python has the following characteristics:
A complex number consists of a real part and an imaginary part, expressed as: real+imagj or real+imagJ.
Both the real part real and the imaginary part imag of a complex number are floating point.
> a = 1binary 2j > a (1cm 2j) # output result > a.real # Real part 1.0 # output result > type (a.real) float # output result > a.imag # imaginary part 2.0 # output result > type (a.imag) float # output result about what is the base of Python and data type is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.