Introduction to Python core programming learning Diary

Source: Internet
Author: User
Tags echo command

Chapter 1 Welcome to python.

  1. Interactive interpreter.
  2. Compile-type programming language: Compile the program source code into the target code (machine language ). Compile the program to translate the original program into the target program and save it in another file.
  3. Interpreted language: In the implementation of interpreted language, the translator does not generate the target machine code, but produces intermediate code that is easy to execute. This intermediate code is different from the machine code. The intermediate code is supported by software and cannot be directly used by hardware. The software interpreter usually causes low execution efficiency. A program written in interpreted language is executed by another interpreter that can understand intermediate code. The difference between precompiled programs is that the task of interpreting programs is to interpret the source program statements one by one as executable machine commands without translating the source program into the target code and then executing it. The advantage of interpreting a program is that when a syntax error occurs in a statement, it can immediately arouse the programmer's interest.
  4. Hybrid mode: Java is very special. Java programs also need to be compiled, but the code is compiled into bytecode, and then the Java virtual machine uses the interpreted method to execute bytecode. Similar to Python, the Python bytecode interpreter is used to interpret and execute bytecode.

Chapter 2: Quick Start

  • Program output, print statement

The print statement is used to display output results on the screen. (C language printf, shell uses the $ echo command .) Python strings are enclosed in single quotes. When the print statement outputs an element separated by commas, a space is automatically added to each other as a separator.

  • Program input and raw_input () built-in functions

Raw_input () reads data from the standard input and then readsStringAssign a value to a specified variable.

Int () (before 1.5, use the string. aoti () function) to convert the input value from the string format to the integer format.

  • Program annotation: In most Script Programming Languages and UNIX shell languages, (#) indicates that the text starting from the appearance of this symbol to the end of the statement line will be a program annotation.
  • Operator: addition, subtraction, multiplication, division, and remainder (+,-, *,/, % ),Multiplication (**). Comparison operators (<,<=, >,>= ),Equal to (=), not equal (! = Or <>). Two non-equal symbols are supported. Try to use the former.

Expression concatenation operator: and, or (or), not ).Python supports expressions similar to (3 <4 <5)

      Most standard types support "+ ". Including values and Sequences

  • Variable and Value assignment: python is case sensitive. The dynamic definition of the variable type, which is determined during the value assignment operation. Therefore, it is unnecessary to predefine variables and their types.

Python supports = assignment, or Incremental assignment similar to * =,N ++ or ++ n.

  • Number: Four numeric types are supported: int (signed integer), long (long integer), float (floating point real number), complex (plural)

    The value range of a long integer in python is the capacity that the user (virtual) memory can represent. Similar to the BigInteger class in Java.

  • String: Definition: continuous character set combination between quotation marks. (Python supports ''and "". Used to use'')

The separator operators include "[]" and "[:]". 0 is the base address of the subscript, and-1 points to the last character. + Is the string merge operator, and * is the repetition operator.

  • List and table column: they are similar to arrays, but they can accommodate different types of objects.

The list is defined by "[]". The element and length are variable. Column names are defined by parentheses. Definition cannot be changed. A table column is similar to a read-only list. Separation operators "[]" and "[:]"

  • Dictionary: Use "{}" to define the data type of a hash table (a pair of key words and values ).
  • Use indentation for code segments
  • If statement: Format: if expression: if_suite (a child code segment composed of one or more statements ). If else, if else if ekse is the same. Except that else if is merged into "elif" Reserved Words. There are no switch or case statements in Python.
  • While statement: Format: while expression: while_suite
  • For Loop and range () built-in functions:

For var in sequence (can be a list, table column, string): for_suite. The range () built-in function generates a list of numbers.

  • File and open () built-in functions
  1. Open a file: handle = open (file_name, access_mode = 'R') and return the handle of a file object.

(File_name is a file name string, access_mode is "r" read operation, "w" write operation, "a" add operation, "+" read/write operation, "B" binary access operation, the default value is read-only operation "r").

  • Error and exception: try: try_running_this_suite handle T someError: suite_if_someError_occurs (exceptions caused by the raise command)
  • Function:

1. Define function: def function_name ([arguments]): "optional documentation string" functuation_suite

2. default parameters.

  • Class: static data member or function declaration (Class Attribute) package container

1. class Definition: class class_name [(base_classes_if_any)]: "optional documentation string" static_member_declarations method_declarations

Self is similar to this in C ++ or Java.

2. Create a class instance:

  • Module: organizes and divides the Python code physically into one file. A module can contain executable code, functions, classes, and various combinations of these things.

1. import template: import module_name call: Point attribute mark access attribute

  

Conclusion: Using an interactive interpreter is a good way for scripting language learners. It can avoid many bad habits. Especially the ':' behind the for and while is always easy to ignore.

    

 

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.