Python Note II (data types and variables, strings, and encodings)

Source: Internet
Author: User
Tags floor division integer division

First, the data type

The types of data that Python can directly handle are: integers, floating-point numbers, strings, booleans, and null values.

Integer

Floating point number

String: Enclose a single quotation mark in double quotation marks to output i ' m ok.

You can also use \ to implement, \ nthe line \ t table

Multi-line string with "'"

Boolean: Boolean values can be performed with or non-op/with and or not

Null value

Second, the variable

A = 1/a = "Nadech" is different from Java, when Python declares a variable without specifying the type of the variable, the direct assignment is OK

When executing a =1, thepython interpreter actually performs two steps: Create an integer 1, declare the variable A, and point the variable A to the integer 1

  Constant PI, even if declared in order to be constant, but Python does not have a true constant

Integer division in Python is accurate:10/3 = 3.333333333333 Floor Division: 10//3=3

Three, string and encoding

ASCII encoding, can only encode 127 characters, so the number is limited

GB2312 (2 bytes) China is used to write Chinese and is built on ASCII code and cannot conflict with ASCII. After that, Korea and Japan all have their own code and so on.

Unicode encoding (2 bytes), unifying all languages into a set of encodings. The disadvantage is 2 bytes, which is a waste of storage space.

UTF-8 encoding encodes a Unicode character into 1-6 bytes based on 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. The advantage of UTF-8 is that it is compatible with ASCII code and saves space.

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.

  

  

  

Python Note II (data types and variables, strings, and encodings)

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