019-python functions and common modules-built-in functions, 019-python built-in

Source: Internet
Author: User

019-python functions and common modules-built-in functions, 019-python built-in

1 #1. abs absolute value 2 n = abs (-1) 3 print (n) 4 # output 5 1 6 7 #2. boolean value 8 #0, None ,"", [], () # The result is False 9 print (bool (0) 10 # output 11 False12 13 #3. True 14 n = all, 3, None]) 15 print (n) 16 # output 17 False18 19 n = all ([1, 2, 4]) 20 print (n) 21 # output 22 True23 24 #4. If there is truth, it will be true 25 n = any ([None, "", 1]) 26 print (n) 27 # output 28 True29 30 #5. Binary, octal, and hexadecimal 31 # bin () binary 32 # oct () Evaluate octal 33 # hex () hexadecimal 34 print (bin (5) 35 print (oct (9) 36 print (hex (15) 37 # output 38 0b10139 0o1140 0xf
1 # One UTF-8 character: Three bytes 2 # gbk one Chinese Character: two bytes 3 # UTF-8 4 s = "Li Jie" 5 # one byte 8 bits, one Chinese character three bytes 6 # String Conversion byte type 7 # bytes (as long as the conversion string, according to what encoding) 8 n = bytes ("Li Jie", encoding = "UTF-8 ") 9 print (n) 10 n = bytes ("Li Jie", encoding = "gbk") 11 print (n) 12 13 # output 14 B '\ xe6 \ x9d \ x8e \ xe6 \ x9d \ xb0' # byte type, display in hexadecimal notation 15 B '\ xc0 \ xee \ xbd \ xdc'
1 # convert byte to string use str () function 2 new_str = str (bytes ("Li Jie", encoding = "UTF-8"), encoding = "UTF-8") 3 print (new_str) 4 # Why is the second encoding not decoding? 5 6 # output 7 Li Jie

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.