Python Basic Series One: First knowledge python (ii) supplements

Source: Internet
Author: User

Basic data types

1, integral type (int)

    • How to create:
      N1 = 123      # based on the Int class, an object is created n2 = Int (123) # An object is created from the Int class
    • int internal optimization

      N1,n2 share the same block of memory,
      • The Int object in Python is the extension of the long type value in the C language
      • Small integer objects [-5, 257] are shared in Python
      • Integer objects are obtained from the buffer pool.

2. String (str)

    • How to create
      S1 = "Hello" s1 = str (' Hello ')
    • String (str) type and bytes type convert py3 version
      STR (bytes_or_buffer[, encoding[, errors]), str
      Name = "Blog Park" for I in Name:    print (i)    bytes_list = bytes (i, encoding= ' utf-8 ')    print (bytes_list)           # By default each byte is 16 binary for the X in  bytes_list:        print (X,bin (x))                # Default Every byte is a 10 binary representation

      Because of the utf-8--3 bytes
      GBK--"2 bytes
      Output Result:

      Bo B ' \xe5\x8d\x9a ' 229 0b11100101141 0b10001101154 0b10011010 guest B ' \xe5\xae\xa2 ' 229 0b11100101174 0b10101110162 0b10100010 Park B ' \xe5\x9b\xad ' 229 0b11100101155 0b10011011173 0b10101101
    • Binary conversions such as:

      

PS: General string execution of a function will generate a new content, the original content is unchanged list,tuple,dict.

3. Dictionary (dict)

    • Small case, take out 123 in the dictionary:
      Li = ["Alex", 123, {"K1": "V1", "K2": {"VV": (11,22,123), "II": 456}]
      Print (li[2][' K2 ' [' VV '][2])
    • The usage of Dict.fromkeys understands:
      a1= Dict.fromkeys ([' K1 ', ' K2 ', ' K3 '],[]) print (A1) a1[' K1 '].append (' 1 ') print (A1)

        



  

Python Basic Series One: First knowledge python (ii) supplements

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.