Python Learning Note III: BASIC syntax

Source: Internet
Author: User

The concept of understanding objects in Python programming is important because its purpose is ' everything is Object '. (Advance notice)

High-level languages such as Python,perl and Java have many similarities. However, there are some differences.

Interactive programming:

Script-type programming

Written by the Python IDE. py

Python identifiers

Case sensitive

Identifiers that begin with _ have special meanings

A class attribute that is not directly accessible by the representative of a single _ (_foo) is required to provide access to the interface provided by the class and cannot be imported with the FROM XXX import * *.

Start with a double underscore (__foo) on behalf of a private member

A __foo__ that begins and ends with a double underscore, which represents a special method-specific identifier for Python, such as __init__ (), which represents the constructor of a class

Python reserved characters

Cannot make any other identifier name, constant, or variable

and Exec Not
Assert Finally Or
Break For Pass
Class From Print
Continue Global Raise
Def If Return
Del Import Try
Elif Inch While
Else Is With
Except Lambda Yield

Line and indent

Python has strict line indentation requirements and uses indentation to write modules. all code blocks must contain the same amount of indentation whitespace.

If True:

Print "True"

Else

Print "False" #错误的

The Python statement takes the new line as the Terminator of the statement . Concatenate a line with a slash (\) to display multiple lines of the statement.

The statement contains [],{}, and () does not require the use of a multiline connector.

days=[' Mon ', ' Tue ', ' Wed ',

' Thu ', ' Fri ']

Comments

#!/usr/bin/python

Blank Line

A blank line separates the methods of a function or class from the beginning of a new code. Class and function entries are also separated by a blank line to highlight the beginning of the function entry.

is not part of the Python language.

Show multiple statements on the same line import sys; x= ' foo '

First, the data type:

Python can process the following data directly without the need to declare it in advance.

Integer, python can handle integers of any size.

Floating-point numbers, which are decimals, must be represented by scientific notation for large or small floating-point numbers, 1.23e9, 1.2e-5

String, "", "' I\ ' m \" ok\ "! ' escape character \ t \ \ \

Print "' Line1

Line2

Line3 ""

Boolean value, True False, 3>2 3>5, and or not

Null value, None, a special null value

Standard data types

Numbers (digital)

Numeric data types are used to store numeric values.

They are immutable data types, which means that changing the numeric data type assigns a new object.

When you specify a value, the number object is created:

int long float Complex

Del Delete Object

Long-integer 51924361L, A+bj--complex (A, B)

String (String)

The Python string list has 2 order of values:

    • Left-to-right index starts at default 0, with a maximum range of 1 less string lengths
    • Right-to-left index starts with default-1, the maximum range is the beginning of the string

List (lists)

Tuple (tuple)

Dictionary (dictionary)

Second, the variable

The value that the variable is stored in memory . This means that there is a space in memory when creating variables.

Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.

Therefore, variables can specify different data types, which can store integers, decimals, or characters.

Assigned value =

Multivariate assignment A, b, C = 1, 2, "John"

Three, constant

Constants are typically represented in all uppercase variable names.

10/3 10.0/3 10%3

Python Learning Note III: BASIC syntax

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.