Getting started with python, python

Source: Internet
Author: User

Getting started with python, python

Python type

Cpython: parses the python code into pyc (python bytecode) using the C language, and then runs it on the python Virtual Machine (the PYTHON we learn is cpython)

Jpython: parses the python code into a java bytecode using the java language, and then runs on the jvm (java Virtual Machine ).

Pypy: Use python to implement python, compile python byte friends into machine code, and then run

 

Code running principle

Process: 1. First, dynamically compile the source code into bytecode 2. Then, compile the bytecode into a machine code through the corresponding virtual machine, and then interact with the CPU Instruction Set for execution.

 

First python Program

[Root @ localhost day1] # cat first. py #! /Usr/bin/env python3 # specify the python interpreter #-*-coding: UTF-8-*-# specify the encoding format print ('Hello world! ') [Root @ localhost day1] # alias pyalias py = 'python3' [root @ localhost day1] # py first. pyhello world!

 

Encoding format

Ascii: The computer content is expressed in 1 byte, that is, it has only eight digits and can contain a maximum of 256 characters. It is enough for English letters, however, other non-English languages show their limitations. Therefore, unicode occurs.

Unicode: a universal code, a single code, is generated to address the limitations of traditional character encoding. It sets a unified and unique binary code for each character in each language, at least two bytes are used for representation.

UTF-8: compresses and optimizes unicode and classifies characters and symbols. For example, ascii occupies one byte and European characters occupies two bytes, asian characters occupy 3 bytes (this encoding format is often used for writing code)

 

Input parameters when executing the script

Python provides the sys module to implement this function. The example is as follows:

[root@localhost day1]# cat args.py#!/usr/bin/env python3import sysprint(sys.argv)[root@localhost day1]# py args.py['args.py'][root@localhost day1]# py args.py arg1 arg2['args.py', 'arg1', 'arg2']

 

Variable

String: single quotation marks, double quotation marks, and three quotation marks (multiple rows). Once defined, a memory space is opened up.

Example: str1 = 'a'; str2 = "aa"; str3 = "" aa \ nbb \ ncc """

Number: integer 32/64 long integer (unlimited length), floating point type, plural

List: An Array

Example: list1 = ['A', 'B', 1]

Tuple: a list that cannot be modified. For example, the week and month are represented by tuples.

Example: tuple1 = ('mon', 'tus ', 'thir',) tuple2 = 1, 2, 3

Dictionary (dict): it may be roughly understood as a key-Value Pair (hash)

Example: dict1 = {'name': 'hoho', 'age': 18}

 

Boolean value: true or false, 1 or 0

Operator

Arithmetic Operation: +-*/** // %

Logical operation: and or not

Member operations: in, not in

Comparison calculation: ><>==! = <>

Identity calculation: is, is not

Value assignment: = + =-= * =/= % = ** =

Bit operation: & | ^ ~ >>< (Rarely used)

 

Process Control

1. Conditional Control (the statement blocks under elif can be omitted, depending on the situation)

If con:

Pass

Elif con2:

Pass

Else:

Pass

 

2. Loop Control

2.1 while Loop

While con:

Pass

2.2 for Loop

For I in list/iter:

Do somethings ..

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.