Python Introductory article

Source: Internet
Author: User
Tags arithmetic goto

Python history

1989, a Boring Christmas night, Dutch Guido wrote Python, named after his favorite comic name, "Monty Python's Flying Circus."

Python version

  • 2.X developed to 2.7.

  • 3.Xs started in 2008, 3.5 posted on September 2015, 3.6 released in December 2016, 3.7 released in 2018 6 June

  • 2.x and 3.x differences

      • Statement is functional, such as print 1 2, but 2.x means print statement printing tuple, 3.x meaning is a function of 2 parameters

      • Divisible, for example 1/2 and 1//2,3.x versions/for natural divide

      • Raw_input renamed as input in 3.x, no longer used

      • Raw_input

      • Round function, the rounding of I.5 in 3.x becomes the nearest even

      • Unicode for uniform use of strings


        • Exception capture, thrown syntax change

Programming Basics
    • Program: A set of programs that enable computers to recognize and execute

    • Electronic computers: machines capable of executing programs

    • Two main characters of computer development:

      • Alan Maschiesen. Turing: Known as the father of the computer

      • Von Neumann: one or two binary system for digital computers based on the number of computers in accordance with the program sequence, the computer should have five parts

von Neumann architecture

The computer should consist of five major components:

    • CPU: Composed of operators and controllers

    • operator : complete a variety of arithmetic operations, logic operations, data processing processing, etc.

    • controller : Execution of the control program

    • There are registers and multilevel caches in the CPU

    • : For memory programs and data, such as memory

    • input device : Enter the data cargo program into your computer, such as the mouse keyboard

    • output device : Displays the results of the data-handling process to the user, such as the display, printer

computer language: The language of human interaction with computers

    • Low-level languages: machine-oriented languages, including machine languages, assembly language

    • High-level language: computer language close to natural language and book math language. High-level language first to write the source program, through the compiler program to convert the source program to machine instructions

    • High-level and low-level languages need a conversion tool: compiler, interpreter
    • c,c++ The source code for the language needs to be compiled locally

    • Java, Python, C # source code needs , run on a virtual machine

    • UL class= "List-paddingleft-2" style= "list-style-type:circle;" >
    • Compiled language: CPU instructions for converting source code to target machine

    • Interpreting language: Interpreting and converting to bytecode, running on virtual machine, interpreter executing intermediate code (JVM,PVM)

    • Unstructured language

      • Number or label, GOTO, subroutine can be made up of multiple entrances and exits

      • There are branches, loops

    • Structured language

      • Any basic structure allows only the only entry and the only exit

      • Order, Branch, loop, discard Goto

    • Object-oriented language

      • Closer to human recognition, everything is abstracted into objects, relationships between objects are abstracted into classes and inherited

      • Encapsulation, inheritance, polymorphism

    • Functional language

Program Programm
    • program = algorithm + data structure
    • Data is at the heart of all Programs

    • Data structure is the type and organization of the information in the computer

    • Algorithm is the way of processing data, the algorithm has the advantages and disadvantages of

Notes to write a program
    1. Clearing data
    2. Clear Processing method
    3. Transform the data design into a structure and transform the processing method into an algorithm
    4. Using the design paradigm to program equipment
    5. There are bugs in the world program . But it's going to debug .

Python interpreter

    1. Official CPYTHON:C language development, the broadest Python interpreter

    2. IPython: Called Brother Interactive, enhanced CPython

    3. Pypy:python language written Python interpreter, JIT technology, dynamically compiled Python code

    4. jython:< The source code for span class= "FONTSTYLE0" >python is compiled into Java bytecode and runs on the JVM

    5. Ironpython:   similar to Jython, running on. NET platform, Python code is compiled into. NET bytecode

Python basic Syntax (partial)

  • Escape sequences

      • \ \ \ \ \ \ \ \ \ \

      • Prefix r, treats all the characters inside as normal characters

  • Cont.:

      • Use at end of line \

      • If you use a variety of parentheses, the parentheses are a whole, without the internal \

  • Identifier:

      • Can only be letters, underscores and numbers

      • Cannot start with a number

      • cannot be a python keyword, exp:def,class cannot be used as an identifier

      • Python is case sensitive

  • Conventions:

      • Not allowed in Chinese

      • Not allowed to use ambiguous words, exp:class_

      • Do not use an identifier that starts with an underscore in python

  • Constant:

      • Once the assignment is not tender, change the identifier of the value

      • Constant literal constants cannot be defined in Python:

      • A separate amount, such as the "ABC" Variable:

      • The identifier of the value can be changed after assignment


    The language type of Python

      • Python is dynamic, strong language type

  • Statically compiled language

      • Declare the variable type beforehand, the type can no longer change

      • Compile-time check

  • Dynamic compilation language

      • No prior life type, can be assigned to other types at any time

      • It is difficult to infer what type is not known when programming

  • Strongly typed languages

      • Operation between different types, you must first force the type to be the same type. Exp:print (' a ' + 1) will error, only print (' a ' + ' 1 ')

  • Weakly typed languages

      • Can be manipulated between different types, auto-implicitly convert exp:javascript in Console.lg (1+ ' a ')

Original code, anti-code, complement, negative representation

  • Original code: 5 = 0b101,1 = 0b1,-1 = -0b1,bin (-1)

  • Anti-code: The inverse code of positive number is the same as the original code, negative number of the anti-code sign bit unchanged, the rest of the bitwise negation

  • Complement: The complement of positive numbers is the same as the original code, the complement sign of negative numbers is unchanged after +1 (negative complement of complement is the original code)

  • Negative representation method

      • Negative numbers are stored in the computer with a complement of 1, with a complement of 1111 1111

      • 5-1 = 5+ (-1) Intuitively is 0b101-0b1, in fact the computer is 0B101+0B111111111.~12 = 13


  • Expressionsexpression: A combination of numbers, symbols, parentheses, variables, etc.

      1. An arithmetic expression

      2. Logical Expressions

      3. Assignment expression: In Python, assignment is defined , and if a variable is already defined, the assignment is equivalent to redefining the value

Memory management

    • Garbage collection Mechanism GC

    • Python programming generally does not care about the survival of variables, generally do not care about memory management

    • Python records the number of references to all objects using the object reference count

    • When the object reference number becomes 0, it can be garbage collected by GC

    • When it comes to performance, you need to consider the reference to the variable, but whether to free up memory or try not to free up memory to see the demand. Exp: the data in this interval cannot be used when the internal release is being sorted

false Equivalent Boolean value, equivalent to bool (value)

1. Empty collection

-Empty string ""

-Empty Ganso ()

-Empty list []

-Empty Dictionary {}

2.None objects

3.0


Python Introductory article

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.