Python Basic Notes

Source: Internet
Author: User

    • Operator

/Division to integers is also division, such as 10/3=3.3333 ...; 10.5/3=3.5

% take-over 10%3=1; 10.5%3=1.5

Rounding 10//3=3;10.5//3=3.0

    • Null value in none,c#.
    • In Python, it is common to use all uppercase variable names to represent constants, just a customary usage that can still change values.
    • Variables: Arbitrary data types can be assigned to variables, the same variable can be repeatedly assigned, and can be different types of variables
    • Coding

At the earliest, only 127 letters were encoded into the computer, that is, letters, numbers, and symbols in uppercase and lowercase, and this coded table is called ASCII coding.

is to deal with Chinese obviously a byte is not enough, need at least two bytes, and can not conflict with ASCII encoding, so, China has developed a GB2312 code to put Chinese into.

Unicode unifies all languages into a set of encodings, so there is no more garbled problem.

ASCII encoding is 1 bytes, while Unicode encoding is usually 2 bytes.

If ASCII encoding is A encoded in Unicode, you only need to make 0 in front.

In the spirit of saving, there has been the conversion of Unicode encoding to "Variable length encoding" UTF-8 encoding. The UTF-8 encoding encodes a Unicode character into 1-6 bytes according to a different number size, the commonly used English letter is encoded in 1 bytes, the kanji is usually 3 bytes, and only the very uncommon characters are encoded into 4-6 bytes. If the text you want to transfer contains a large number of English characters, you can save space by coding with UTF-8

Character

Ascii

Unicode

UTF-8

A

01000001

0000000001000001

01000001

In

X

01001110 00101101

11100100 10111000 10101101

In computer memory, Unicode encoding is used uniformly, and is converted to UTF-8 encoding when it needs to be saved to the hard disk or when it needs to be transferred.

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.

When you browse the Web, the server converts dynamically generated Unicode content to UTF-8 and then to the browser:

    • In the latest version of Python 3, strings are encoded in Unicode, meaning that Python's strings support multiple languages

Python provides an ord() integer representation of the function to get the character, and the chr() function converts the encoding to the corresponding character;

Ord (' Zhang ') =24352

    • Formatting

In Python, the format used is consistent with the C language, with % implementation,%s,%d,%f ....

    • The List index is supported by the reciprocal [] representation
test = [‘Michael‘, ‘Bob‘, ‘Tracy‘]
test[0]   test[1]  
test[-1]倒数第一个  test[-2]倒数第二个
The data type of the elements in the list can also be different, and the list element can be another list

    • Tuple () indicates
classmates = (‘Michael‘, ‘Bob‘, ‘Tracy‘)
Once a tuple is initialized, it cannot be modified, but if the element is a list,list value can be changed. Similar to the reference immutable in C #, the properties of the referenced object can be changed.
A tuple of only 1 elements must be defined with a comma , to disambiguate: t= (1,)

Python Basic Notes

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.