Python basic syntax

Source: Internet
Author: User

By default, the Python3 source file is encoded in Utf-8.

Identifiers are numbered, alphabetic, underlined, and the first letter does not apply to numbers. is case sensitive.

Annotate with #: #这是注释

Use indentation to represent a block of code, without curly braces {}. However, statements within the same code block must contain the same number of blank cells:

if True:     Print ("True") Else :     Print ("False")

Use backslashes \ To implement interlacing:

Total = Item_one +         +         item_three
View Code

Multi-line statements in (), [], {} Do not require a backslash:

1 total = ['item_one'item_two'item_ Three',2         'item_four' item_five ']

There are only four types of numeric values :

integers, long integers, floating-point numbers, complex numbers (1.1+2.3j)

string :

* Single quotes and double quotes work the same

* Three quotation marks can specify a multiline character

* Escape character "\"

* string preceded by R or R, the escaped string will be displayed as an acoustic string: R "This was a line with \ n"

* string is not variable

* String pre-plus u, as Unicode processing

Blank line :

The function or class method is separated by a blank line.

The print () statement outputs a line wrap, which can be added end= "":

# No line break output Print (x, end=""  ) Print (Y, end=""  ) Print ()
View Code

code group :

Indenting the same set of statements is called a code group. The first line of If/esle, while, starts with the keyword and ends with a colon (:). The code group after the first line becomes a clause.

if expression:    suite   # clause elif  expression:    Else :    Suite

Module Import:

entire module import: Import Somemodule Import a function of a module: # Import a  from Import somefunction # Import Multiple  from Import Firstfunc, Secondfunc, Thirdfunc # Import All  from Import *
View Code

Command-line arguments:

Python can use the-H parameter to view the Help information for each parameter

The variable does not need to be declared, and is created after the value is assigned. The variable itself has no so-called "type", generally refers to the type of object that it refers to in memory.

Multiple variables can be assigned values such as: a=b=c=1

Or: A, B, C = 1, 2, "Runoob"

Standard data types

Number:int (long) float (floating point) bool complex (plural)

Language built-in type () function query type print (type (a))---"<class ' int ' >

Type () differs from instance (). Type Otherwise the subclass instance belongs to the parent class instance admits that the instance of the subclass belongs to the parent class type.

Division operator/always return a floating point, to take integer with//operator

When blending, Python converts the integer type to floating point.

String

Tuple

List

Sets

Dictionary

Python 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.