Python3-day1 (basic summary)

Source: Internet
Author: User

Summarize the difficulty of comparing abstract:

1. Binary operations

& 13 =12

60 | 13 =61

60 ^ 13 =49

60<<2 =240

60>>2 =15

2. Logical operators

And Or not

3. Relational operators

In No in

4. Validation operators

Is isn't

5. Character encoding

ASCII uses only 8bit, that is, 1byte can only represent 255 characters, and is sufficient for Europe and the United States. But other non-English language languages cannot include, for example, China's gb2312, and countries have their own standards.

Therefore Unicode appears, can include all countries encoded text, usually 2bytes, special needs 4bytes.

Finally utf-8 in the spirit of saving, combined with ASCII and Unicode, is a variable length code, is also common to all of us.

Ascii->unicode->utf-8

Note: In computer memory, Unicode is used uniformly and is converted to utf-8 when it needs to be saved to the hard disk or transmitted.

When editing with Notepad, the UTF-8 characters read from the file are converted to Unicode characters into memory, and when the edits are complete, the conversion of Unicode to UTF-8 is saved to the file.

  

ASCII conversion warrants for Python:

>>> Ord (' A ')

65

>>> Chr (65)

A

python2.7 can be used in

    >>> u ' abc '. Encode (' Utf-8 ') #unicode---Utf-8

' ABC '

>>> ' abc '. Decode (' Utf-8 ') #utf-8---Unicode

U ' abc '

Unicode is used uniformly in python3.x, plus no U is the same, only the string in bytes must be preceded by B, i.e. B "ABC"

>>>a= ' Tom '

>>>a.encode (' Utf-8 ')

B ' Tom '

>>> a= ' China '

>>> A

China

>>> a.encode (' Utf-8 ')

B ' \XE4\XB8\XAD\XE5\X9B\XBD '

6.list list (Python's fine with)

namelist=[' Tom ', ' Apple ', ' cat ', ' Tom '

Dir (namelist)

Namelist.append (' Tom ')

Namelist.index (' Tom ')

Namelist.count (' Tom ')

Namelist.remove (' Tom ')

Namelist.sort ()

Namelist.reverse ()

Namelist.pop ()

Namelist.insert (2, ' Tom ')

Namelist.clear ()

namelist[:]

Namelist.extend (Otherlist)

If ' Tom ' in NameList:

Print (' OK ')

For I in range (Namelist.count (' Tom ')):

Namelist.remove (' Tom ')

Python3-day1 (basic summary)

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.