Python core programming 2nd Reading Notes (continuous recording)

Source: Internet
Author: User

Chapter 1 Quick Start

2.4 Operator

1. The double star number (**) is a multiplication operator, for example, 3 ** 2, which means 3 ^ 2.

2. Python supports expressions like "3 <4 <5", which is different from general advanced languages.

3. Python does not support the auto-increment 1 and auto-increment 1 operators in C. On the contrary, because-and + are single object operators, -- n is interpreted as-(-n), and the final result is n, while ++ n is n.

2.5 variables and assignments

1. Python is a dynamic type language and does not need to declare the type of the variable in advance. The type and value of the variable are initialized at the moment of value assignment.


2.7 string

1. Strings in Python are defined as character set combinations between quotation marks. Python supports pair single or double quotation marks. Three quotation marks can be used to contain special characters. You can use the index operator ([]) and slice operator ([:]) (to represent a range, before and after opening) to obtain a substring. The index of the first character is 0, and the index of the last character is-1. The plus sign (+) is used for String concatenation, And the asterisk (*) is used for repeated strings.


2.8 list and metadata

1. Lists and meta-groups can be used as common "arrays", which can store any number of Python objects of any type (the same list or tuples can contain different objects ). The list can be read and written, and the tuples are read-only.


2.10 code block and indent alignment

1. The code block uses indentation alignment to express the code logic, rather than braces.


Chapter 2 Python Basics

Overview:

1. # indicates that the subsequent characters are Python comments.

2. line feed (\ n) is the standard line separator.

3. backslash (\) continues the previous line.

4. Use a semicolon to connect two statements to one line.

5. The colon separates the header and body of the code block. (For/while/if/else, and function definition ).

6. Separate different code blocks with different indentions.

7. Python files are organized as modules. (I can import a previously written. py file in my. py file in the format of import XXX without the. py suffix .)


3.2 variable assignment

1. in Python, objects are passed through references. When assigning a value, whether the object is newly created or an existing one, the reference (not a value) of the object is assigned to the variable. (I personally think it is similar to the reference of C ++, but it is different .)

2. In Python, there is no auto-incrementing operator.

3. You can assign multiple values in Python, for example, x, y, z =, 'AB'


3.4. Basic style:

(1) start line ,#! \ Usr \ bin \ env python

(2) module documentation

(3) module Import

(4) variable definition

(5) Class Definition

(6) Function Definition

(7) Main Program


Chapter 2 Python objects

4.3 None -- Null Object of Python

4.5 comparison of object identities

1. The object identity can be generally considered as the memory address of the object. For example, id (a) = id (B)

2. the built-in type function is used to determine the object type. A very special type is also an object.


Chapter 2 sequence: String, list, and element group



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.