Python Study Notes (2): Basic Concepts

Source: Internet
Author: User
1. Constants

Python constants are different from C # constants. Python constants do not have a name. Such as 2, 1.5, 1.2e-3, or 'this is a string', "It's a string. Unlike C #, it must be identified by the const keyword.

2. Number

Python has four types of numbers: integer, long integer, floating point, and plural. Example:

* INTEGER: 2

* Long Integer: an integer greater than 65535

* Floating point: 1.2, 1.2e-3, e is the power of 10, and 1.2e-3 indicates 1.2*10-3

* Plural: (-5 + 4j), (1.2 + 2.3j)

3. String

Python does not have the char type. Single quotes and double quotes are exactly the same. Example:

* Single quotes: 'quote me on this'

* Double quotation marks: "waht's your name"

* Three quotation marks: ''' this is the first line.

This is the second line .'''

Or

"What's your name?

My name is known ."""

* Escape Character: 'What \'s your name? '

* Natural string: Start with R or R, R "Hello world! \ N"

4. Variables

Identifier naming rules:

* The first character is a letter (both uppercase and lowercase) or an underscore (_)

* Other characters are uppercase/lowercase letters, numbers, and underscores.

* Case sensitive. myname and myname are two different variables.

5. Data Type

The basic data types of Python are numbers and strings, and the advanced types are classes.

6. Object

Python regards everything as an object, and it regards the number 2 as an object.

7. logical and physical rows

The physical line is what you see in the editor. The logic line can be identified by python. Generally, Python considers a physical row to correspond to a logical row.

If you want to use multiple logical rows in a physical row, you must use a semicolon (;) to separate the rows. A semicolon indicates the end of a logical row or statement. We recommend that you do not write it like this, which is less readable.

Example: I = 5; print (I)

Equivalent

I = 5

Print (I)

If you want to write a logical row in multiple physical rows, use a backslash (\) to connect.

Example: S = "This Is \

String"

Equivalent

S = "this is a string"

8. indent

Indentation is important in Python. The blank at the beginning of the line is important, for example:

Print ("hello ")

Print ("world ")

The second print statement reports an error because there is a blank error before it.

Statements at the consent level must have the same indentation.

Do not mix spaces and tabs, so that they will not work on different platforms.

We strongly recommend that you use a single tab or two or four spaces when indent. We recommend that you use four spaces as always.

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.