In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the knowledge points of python numbers". In the daily operation, I believe that many people have doubts about the knowledge points of python numbers. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the knowledge points of python numbers?" Next, please follow the editor to study!
Numbers in python are immutable objects, such as int, float, complex, and bool.
Shaping
Small number pool: range from-5 to 256. when the value is in this range, the interpreter does not need to create a new object, but directly assigns the id corresponding to the value in the cache to the variable.
# Test the following code in the repl environment > axi255 > > bread255 > print (id (a), id (b)) #-5 to 256: out:140728491521632 140728491521632 # an and b have the same id > > axi257 > print (id (a), id (b)) #-5 to 256 out:2083422435600 2083422435632 # an and b have different id
Range of values: shaping in python does not distinguish between short shaping, shaping, and long shaping. The interpreter will dynamically allocate storage space according to the size of the number, and the range of values is only limited by the size of memory.
Import sysa = 1000b = 999999999999999999999c = b**2print (sys.getsizeof (a)) print (sys.getsizeof (b)) print (sys.getsizeof (c)) out:283644
Floating point type
Memory consumption: floating-point in python is equivalent to double-precision floating-point in other programming languages, taking up 24 bytes of memory space. There is no single-precision floating point in python.
Import sysa = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999988888888b = 0.1print (sys.getsizeof (a), sys.getsizeof (b)) out:24
Range of values: the range of floating-point values can be viewed as follows.
Import sysprint (sys.float_info) out:sys.float_info (max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1) plural
The concept of complex number in python is exactly the same as that in mathematics. It is rarely used in practical programming, only in very few situations where scientific computing is needed. I am not going to repeat it here.
Boolean
The Boolean type of python is very special and needs to be combed. Boolean is a logical judgment, and there are only two kinds of judgment:
True: it means true.
Strings, tuples, lists, dictionaries, collections, instances of classes, etc., if the value is not empty, it is determined to be True.
Shaping, floating point, plural, the value is not 0 is determined to be True.
False: indicates false.
Strings, tuples, lists, dictionaries, collections, instances of classes, etc., empty values are determined to be True.
Shaping, floating-point type, plural, the value of 0 is determined to be False.
None, determined as False. None has no meaning, that is, the value and type are not determined. Make a clear distinction between None and null: None indicates that the value is not assigned and the type is not determined, while null indicates that the value is not assigned but the type is determined.
The Boolean decision setting of python is very special, and you can write very concise code after you master it. Let me give you a concise and practical code example.
# remove the element list1 = ['aa',' adc', 'bb',' cc', 'aa',' abc', 'dd'] length= len (list1) while length: # in the list equivalent to while length==0 if list1 [length-1] [0] = =' averse: del list1 [length-1] length-= 1print (list1) out: ['bb',' cc' 'dd'] # check whether there are duplicate records in the sequence And informed that several records had been repeated. List1 = [1,1,2,3,4,5] list2 = [1,2,3,4,5,6] check_repeat = lambda x: len (x)-len (set (x)) # input sequence Returns the difference between the original length and the deduplicated length of the sequence if repeat_num: = check_repeat (list1): # equivalent to check_repeat (list1) > 0 print (list1, f' has {repeat_num} duplicate records') else: print (list1,'no duplicate records') if repeat_num: = check_repeat (list2): print (list1, f' has {repeat_num} duplicate records') else: print (list1 'no duplicate record') out: [1, 1, 2, 3, 4, 5] there is one duplicate record [1, 1, 2, 3, 4, 5] not repeated here The study of "what are the knowledge points of python numbers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.