Two. Python Basic data type

Source: Internet
Author: User
Tags truncated

1. Operators

Define two variables A = ten B = 20

Arithmetic operations

Comparison operation

Assignment operations

Logical operations

Member operations

2. Basic data types

int (integer)

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807float (floating point)Floating-point numbers, which are decimals, are called floating-point numbers because, when represented by scientific notation, the decimal position of a floating-point number is variable, for example, 1.23x109 and 12.3x108 are exactly equal.

String (String)

The strings in Python are enclosed in single quotation marks (') or double quotation marks ("), and the special characters are escaped with a backslash (\).

The index value starts with 0, and 1 is the starting position from the end.

String Common functions:
    • Remove whitespace
    • Segmentation
    • Length
    • Index
    • Slice

List (lists)

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

A list can accomplish the data structure implementation of most collection classes. The types of elements in a list can be different, it supports numbers, and strings can even contain lists (so-called nesting).

A list is a comma-delimited list of elements written between square brackets ([]).

As with strings, lists can also be indexed and truncated, and a new list containing the required elements is returned when the list is truncated.

List = ['ABCD', 786, 2.23,'Runoob', 70.2]tinylist= [123,'Runoob'] Print(list)#Output Complete listPrint(List[0])#The first element of the output listPrint(List[1:3])#output from the second start to a third elementPrint(list[2:])#outputs all elements starting from the third elementPrint(Tinylist * 2)#output Two-time listPrint(List + tinylist)#Connection List

Tuple (tuple)

Tuple (tuple) is similar to a list, except that the elements of a tuple cannot be modified. Tuples are written in parentheses (()), and the elements are separated by commas.

Sets (collection)

A collection (set) is a sequence of unordered, non-repeating elements.

The basic function is to test the membership and remove duplicate elements.

You can create a collection using the curly braces {} or the set () function, note: Creating an empty collection must be set () instead of {}, because {} is used to create an empty dictionary.

Dictionary (dictionary)

A list is an ordered combination of objects, and a dictionary is a collection of unordered objects. The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.

A dictionary is a type of mapping that is identified by the dictionary with "{}", which is an unordered key (key): The value pair collection.

The key (key) must use the immutable type.

In the same dictionary, the key must be unique.

python data type conversions

Two. Python Basic data type

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.