Python basic Syntax (ii)

Source: Internet
Author: User
Tags python list

1, Python can use quotation marks ('), double quotation marks ("), three quotation marks (" "or" ") to denote a string, the beginning and end of the quotation mark must be the same type;

2, single-line comments in Python using # start;

3. Multiple lines of comments in Python use three single quotation marks ("') or three double quotation marks (" ");

4, empty line is also part of the program code;

5, Python can use more than one statement in the same line, between statements using semicolons (;) split; \ n to implement line wrapping;

6, Python can use multiple statements in the same line, between statements using semicolons (;) segmentation;

7, the print default output is a newline, if you want to implement a non-wrapping need to add a comma at the end of the variable;

8. Compound statements such as if, while, Def, and class, the first line begins with a keyword, ends with a colon (:), (indents the same set of statements that make up a block of code, which we call the code group)

9, the variable assignment in Python does not require a type declaration; Each variable must be assigned before it is used, and the variable will not be created until it is assigned.

The equals sign (=) is used to assign a value to a variable. The left side of the equals sign (=) operator is a variable name, and the right side of the equals sign (=) operator is the value stored in the variable.

10, multiple variable assignment;

A = b = c = 1;
A, b, C = 1, 2, "Bob"

11. Python has five standard data types:
Numbers (digital)
String (String)
list (lists)
tuple (tuple)
Dictionary (dictionary)
----------------------------------------------------------------------------------------
python numbers

VAR1 = 1
VAR2 = 2
VAR3 = 3

Del Var1[,var2[,var3[....,varn]]] (del statement to delete references to some objects)

del var ****** del var_a, Var_b (del statement deletes a reference to a single or multiple objects)

Python supports four different types of numbers:
int (signed integral type)
Long (longer integer [can also represent octal and hexadecimal])
Float (float type)
Complex (plural)
-------------------------------------------------------------------------------------
Python string

A string or series (string) is a string of characters consisting of numbers, letters, and underscores.

Generally recorded as:

s= "A1A2 An "(n>=0)

The index from left to right starts with the default of 0, and the maximum range is 1 less string length;

Right-to-left indexing starts with default-1, and the maximum range is the beginning of the string;

Where the subscript is starting from 0, can be positive or negative, subscript can be empty to take the head or tail;
-------------------------------------------------------------------------------------
Python list

The list is the most frequently used data type in Python.

A list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, and strings that can even contain lists (that is, nesting).

The list is identified by [], which is the most common type of composite data for Python.

The interception of the values in the list can also be used for variables [header subscript: tail subscript], starting from left to right index default 0, right-to-left index default-1, subscript can be empty to take the head or tail.

The list of combinations (directly with the + sign, the effect is similar to the JS array merge)
-------------------------------------------------------------------------------------
Python tuples

A tuple is another data type, similar to a list.

The tuple is identified with a "()". The inner elements are separated by commas. However, tuples cannot be assigned two times, which is equivalent to a read-only list.

Combination of tuples (directly with the + sign, the effect is similar to the JS array merge)

The difference between tuples and lists is that tuples are not allowed to be updated (re-assigned), and lists are allowed to be updated;
-------------------------------------------------------------------------------------
Python Dictionary

The Dictionary (dictionary) is the most flexible built-in data structure type in Python, except for lists. A list is an ordered collection of objects, and a dictionary is an unordered collection of objects.

The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.

The dictionary is identified with "{}". A dictionary consists of an index (key) and a value corresponding to it.

The dictionary is similar to the operation of the object in JS, the dictionary. Keys () # Outputs all keys/dictionaries. VALUES () # Outputs all values (like object traversal methods)

Conversion of data types, just use the data type as a function name!

Python basic Syntax (ii)

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.