Python basic 2 encoding and logical operators

Source: Internet
Author: User
Tags logical operators

Coding:

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)

1024byte=1kb

1024kb==1mb

1024mb=1gb

1024gb==1tb

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)

Results:

False

conversion between INT and bool:

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

Results:

12

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

Results:

Truetruefalse

Interview questions:

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

Examples:

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

The result is:

38-1

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

Example:

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

The result is:

5xx
Example:
Print or or  and or 2)

The result is:

3

 The use of in and not:

Example

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

Results:

TrueFalse

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

Answer:

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

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.