Python command line code Enhanced memory

Source: Internet
Author: User

The Python command line is widely used. We have many difficulties when using it. Let's take a detailed look at how to solve these problems. I hope you will be helpful in later use.

When I was a beginner in Python command line and encountered many coding problems, I wrote it down so that I could not forget it in the future. Many things do not understand it. It was not difficult to understand and draw conclusions. However, when I thought of it, I could help some enthusiastic people to point out the error, then you have a thick face ......

First, you need to know that Python has two types of strings (strictly speaking, this does not seem to be the case ). One is an ordinary str object, each character is represented by 8 bits), the other is a unicode string, they can be converted to each other.
Open pyshell and enter a piece of code.

Python code

 
 
  1. >>> A = "I"
  2. >>> B = unicode (a, "gb2312 ")
  3. >>> A. _ class __
  4. <Type 'str'>
  5. >>> B. _ class __
  6. <Type 'unicode '>
  7. >>>

See the two strings. Come back

Python code

 
 
  1. >>> a   
  2. '\xce\xd2'   
  3. >>> b   
  4. u'\u6211'  

Variable a is a string of two characters, and variable B is a unicode character. For The two types of Strings, The Python documentation --> javasagereference --> DataModel --> The standard type hierarchy --> Sequences has some Strings and Unicode descriptions. As

Python command line code

 
 
  1. >>> Z = u "I"
  2. >>># This type of code is actually nothing.
  3. >>> Z. _ class __
  4. <Type 'unicode '>
  5. >>> Z
  6. U' \ xce \ xd2'

You see, this strange thing ...... later, I tried it in Windows XP and python command lines. Different conclusions are drawn. The result of z is changed to U' \ u6211 '. Here we should not try it in pyshell, it seems that there are still many questions that have not been clearly understood

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.