Python learning notes language, debugging, syntax, variables, expressions

Source: Internet
Author: User

Python: a programming language with the power and versatility of traditional programming languages. It also draws on the ease of use of simple scripts and interpretation languages. To sum up one sentence, it is very good and powerful!

1. The programming language is the programming language, and the program calculates the obtained data according to the instructions provided by the language in a certain logical order, and a combination of commands and data that are finally returned to us.
There are two languages:

 
 
  1. Low-level language: commands executed by computers are abbreviated as English words or words, which greatly improves programming efficiency and program readability.
  2. Advanced Language: it is the procedural, digital, and precise mathematical description of human logic thinking. There are two methods to translate into machine code: Interpretation and compilation.


Interpreted language means reading the source program and executing it)
 

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201208/195946684.jpg "/>


Compile-type languages compile the source code into the target code and then execute the code. You do not need to compile the code later. See)
 

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12591C230-1.jpg "/>

2. debugging

Debugging: the process of solving program errors is called debugging.
Program errors are divided into three types:

 
 
  1. Syntax Error syntax errors): syntax indicates that the composition of Program Statements must comply with the language composition rules. If the statements are not written according to the rules, a syntax error occurs.
  2. Running error runtime errors): A series of unpredictable errors that occur during the running of the program, which causes the program to fail to run normally or be affected.
  3. Semantic Error semantic errors): even if a program has semantic errors, it can run normally without generating any error information. However, the results are quite different from what we expected and it is difficult to troubleshoot such errors.


3. python Program
Python is an interpreted language. We can execute Python programs in command line or script mode.
Enter the Python command in the terminal and enter the command line mode. The Interpreter displays the welcome information, version number, and copyright description .)

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1259164635-2.jpg "/>

 
 
  1. print “Hellow World!” 

This is an example of a print statement. "print" does not mean to be printed on paper, but on the screen. The quotation marks in the Program indicate the start and end of the value, and it does not appear in the result.
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1259162924-3.jpg "/>

4. Variables

Variable: The variable refers to the names of various types of values. When a value is used later, you can directly reference this name without writing a specific value.
The type is not fixed. You can assign an integer to a variable. If you think it is inappropriate, you can assign a string to it.

 
 
  1. X = 100 # case sensitive
  2. Print x # integer int)

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12591CU9-4.jpg "/>

 
 
  1. X = "China"
  2. Print x # string type

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1259164b0-5.jpg "/>

If you cannot determine the type of the variable or data, use the built-in function type in the interpreter to confirm the content of the variable type.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12591C9B-6.jpg "/>

5. variable name

A variable name can be a string of any length consisting of numbers and characters, but must start with a letter.
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1259163K0-7.jpg "/>

For example, two variables are defined. The first letter is case-insensitive and the output content is different.

Note: The variable name cannot start with a number, cannot contain invalid characters $ % @), and cannot contain keywords drafted by python. A total of 28 keywords are drafted by python:

 
 
  1. and continue else for import not raise 
  2. assert def except from in or return 
  3. break del exec global is pass try 
  4. class elif finally if lambda print while 

6. Statements

A statement is a command that can be executed by the Python interpreter. We already know two statements: Print and assign values.

 
 
  1. The value assignment statement has two functions:
  2. First, create new variables,
  3. Second, assign the value to the variable.
  4. All variables must be assigned a value. Otherwise, it is regarded as a non-existent variable.

In general, we use a status chart to indicate the state of a variable. On the left is the variable name, on the right is the variable value, and the arrow in the middle points to the value. The status chart shows the final operation result of the value assignment statement.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1259163Q0-8.jpg "/>

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12591A1a-9.jpg "/>

Print the calculation result of the print Output expression. A single variable can also be seen as an expression. If you want to print multiple variables in one row, you can use commas to separate these variables. line breaks are prohibited.

 
 
  1. >>> x = 3 
  2. >>> y = 8.9 
  3. >>> print x, y, "hello", 9 
  4. 3 8.9 hello 9 
  5. >>> print x, '\t', y, "\t", "hello", "\t", 9 
  6. 3 8.9 hello 9 

The second print statement separates these variables with tabs. Below are some special printing methods:

 
 
  1. >>># Print single quotes
  2. >>> Print "''"
  3. ''
  4. >>># Print double quotation marks
  5. >>> Print '""'
  6. ""
  7. >>># Print line breaks
  8. >>> Print '\ N'
  9. >>># Print the backslash
  10. >>> Print '\\'
  11. \

7. Expressions

An expression is composed of values, variables, and operators. If you enter an expression on the command line, the interpreter wakes up the calculation and displays the result:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1259163R1-10.jpg "/>

A single value or variable can also be treated as an expression:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/12591A1K-11.jpg "/>

The calculated expression and the printed value are quite distinct.

 
 
  1. >>> "I am free!" 
  2. 'I am free!' 
  3. >>> message = "I am free!" 
  4. >>> message 
  5. 'I am free!' 
  6. >>> print message 
  7. I am free! 
  8. >>> print "I am free!" 
  9. I am free! 

When Python displays the expression value, the display format is the same as the format you entered. If it is a string, it means it contains quotation marks. The output results of printed statements do not include quotation marks, but only the content of strings.
 

This article comes from "My future is not a dream ." Blog, please be sure to keep this source http://song49.blog.51cto.com/4480450/956428

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.