Python's combination of data types, logical operators, control flow statements, arithmetic operators

Source: Internet
Author: User
Tags arithmetic arithmetic operators logical operators in python
Commonly used composite data types in Python

Sequence type

List: Use ' [] ' to create, such as ["Hello", "World", "Hello", "Python"], the list is a Mutable object, supporting the original modification (that is, it can be directly in memory in place to make changes), support for the data itself to make changes (see Figure 1)

Tuples: Using ' () ' to create, such as (' Hello ', ' world '), tuples are immutable objects

String: The string is also a sequence type, and the string can be sliced and referenced (see Figure 2), note: The slice itself is creating a new object because the string is immutable, so the sliced slice is a new object.

In fact, lists and tuples do not really store data, but rather hold object references.

Collection type

Collection

Mapping type

Dictionary

"Figure 1"

"Figure 2"




Python logical operators

Identity operator

is: Determines whether the left-side object reference is the same Yu Yu-side object reference;

comparison operator

<, >, <, =, >, =,!=, = =

Member operator

In, not in: testing member relationships

logical operators

And, or, not




Python Control flow statement

If: conditional judgment, can be a single branch, two branches, multiple branches, in Python branches need to add ': ' number

While

For ... in

Try: Do an exception capture



Python arithmetic operators

Provides a complete set of arithmetic operations in Python, a lot of Python data types can also use enhanced assignment operators, such as + +, =, *=,%, and so on; the performance of the enhanced assignment operator is better than the agreed function; because Python's int type is immutable objects, So the actual process of an enhanced assignment is to create a new object to store the result and then rebind the variable name

Related Article

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.