Python basic 2 encoding and logical operators

Source: Internet
Author: User
Tags logical operators


ASCII code: The standard ASCII code is encoded using a 7-bit binary code, and when the ASCII code is represented by 1 bytes (8-bit binary code), 1 0 is added at the highest bit.

An English letter takes up one byte

8-bit (bit) = = one byte (byte)





Unicode: in order to solve the problem of the globalization of ASCII, there was a unicode,unicode stipulation that a Chinese is expressed in 4 bytes, and an English is expressed in 1 bytes.

Utf-8: In fact, the upgrade version of Unicode, the provision of English with 1 bytes, Chinese characters are represented by 3 bytes.

Logical operators:

Logical operators have not,or, and.

The operation precedence of these operators is: () >not>and>or

Equal priority left-to-right start operation

For example:

 and or  and or 9 < 8)print(a)



conversion between INT and bool:

a=Int (True) B=int (False)print(A, B)



Rint (BOOL (1))print(bool (3))print(bool (0))



Interview questions:

1. Print (x or y), if X is true, the result is x. Otherwise the result is Y.


Print or 5)printor 8)print( -1or 0)

The result is:


2. Print (x and y), if X is true, the result is Y, and if Y is false, the result is X.


Print  and 5)print and 8)print and 0)

The result is:

Print or or  and or 2)

The result is:


 The use of in and not:


Sl="abcdefg"print("a" in SL) Print ("ad"in#"ad" is equivalent to an element as a whole, instead of "a" "B" being disassembled like this.) 



Title: The content of the commentary can not have sensitive words such as "Xi Big", "Kuomintang", "Chiang Kai-shek"


Comment=input ("Please enter a comment")if("XI greatly"inchComment)or("KMT" inchComment)or("Chiang Kai"inchcomment):Print("the comments contain sensitive words")Else:    Print("Comment Success")

Note: The key to this problem is that the sensitive word should be in comments instead of commet in sensitive words.


Python basic 2 encoding and logical operators

Related Article

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: 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.