Little Ha Co python lesson three-character set encoding

Source: Internet
Author: User
Tags python script

content Encoding
    1. The Python interpreter encodes the content when it loads the code in the. py file (default Ascill)
    2. ASCII (American Standard Code for Information interchange, United States Standards Information Interchange Code) is a set of computer coding systems based on the Latin alphabet, mainly used to display modern English and other Western European languages, which can be used up to 8 Bit to represent (one byte), that is: 2**8 = 256, so the ASCII code can only represent a maximum of 256 symbols.
    3. It is clear that the ASCII code cannot represent all the words and symbols in the world, so it is necessary to create a new encoding that can represent all the characters and symbols, namely: Unicode

      Unicode (Uniform Code, universal Code, single code) is a character encoding used on a computer. Unicode is created to address the limitations of the traditional character encoding scheme, which sets a uniform and unique binary encoding for each character in each language, which specifies that characters and symbols are represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536,
      Note: Here is a minimum of 2 bytes, possibly more

      UTF-8, which is compression and optimization of Unicode encoding, does not use a minimum of 2 bytes, but instead classifies all characters and symbols: the contents of the ASCII code are saved with 1 bytes, the characters in Europe are saved in 2 bytes, and the characters in East Asia are saved in 3 bytes ...

Comments
    1. When the line stares: # is annotated content

    2. Multiline Comment: "" "Annotated Content" ""
Execute script incoming parameters

Python has a large number of modules, which makes developing Python programs very concise. The class library includes three:

      • Python-supplied modules
      • Industry-Open Source modules
      • Modules developed by programmers themselves

Python internally provides a SYS module where SYS.ARGV is used to capture parameters passed in when executing a python script

# !/usr/bin/env python # -*-coding:utf-8-*- "Wupeiqi"    

PYc File

When you execute Python code, if you import a different. py file, a. pyc file with the same name is automatically generated during execution, which is the bytecode generated after the Python interpreter was compiled.

Variable
    1. declaring variables
1 # !/usr/bin/env python 2 3 # -*-coding:utf-8-*- 4   5 " Wupeiqi "

The code above declares a variable named: Name, and the value of the variable name is: "Wupeiqi"

2. Rules for variable definitions:

      1. Variable names can only be any combination of letters, numbers, or underscores
      2. The first character of a variable name cannot be a number
      3. The following keywords cannot be declared as variable names [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' fi Nally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' t Ry ', ' while ', ' with ', ' yield ']

3. Assigning values to variables

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 " Wupeiqi " 5 " Alex "

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 " Wupeiqi " 5 name2 = name1

Input
1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3   4 # assigning user-entered content to the name variable 5 name = Raw_input (" Please enter user name:")6   7  #  Print the input content 8 Print Name

When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely:

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3   4 ImportGetpass5   6 #assigning user-entered content to the name variable7PWD = Getpass.getpass ("Please enter your password:")8   9 #Print What you have enteredTen PrintPwd

Little Ha Co python lesson three-character set encoding

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.