Python Learning note 02 python data type 2

Source: Internet
Author: User

The main difference between a list and a tuple is that the list is enclosed in parentheses ([]) and their elements and sizes can be changed, while tuples are in parentheses () and cannot be updated. Tuples can be thought of as read-only lists.

Values stored in a list can be accessed using the slice operator ([] and [:]) with the index starting at 0, at the beginning of the list and ending with-1. The plus sign (+) symbol lists the join operator, and the asterisk (*) repeats the operation.

A python dictionary is a hash table type. They are made up of key-value pairs like associative arrays or hashes in Perl. The dictionary key can be almost any Python type, but it is usually a number or a string. The value can be any Python object.

The dictionary is composed of curly braces ({}), which can be assigned a value and accessed with square brackets ([]).

Sometimes, you might need to perform a conversion between built-in types. Conversions between types, simply use the class masterpiece as a function.

There are several built-in features that convert from one data type to another. These functions return a new object that represents the converted value.

Data type conversions:
function Description

int (x [, Base])

Converts x to an integer. The cardinality is specified as base, if X is a string.

Long (x [, Base])

Converts x to a long integer. The cardinality is specified as base, if X is a string.

Float (x)

Converts an X to a floating-point number.

Complex (real [, Imag])

Creates a complex number.

STR (x)

Convert object x to a string representation.

REPR (x)

Object x is converted to an expression string.

eval (str)

Computes a string and returns an object.

Tuple (s)

Converts s to a tuple.

List (s)

Convert s to a list.

Set (s)

Converts s to a collection.

Dict (d)

Create a dictionary. D must be the (key, value) tuple sequence.

Frozenset (s)

Converts s to frozen set.

Chr (x)

Integers are converted to one character.

UNICHR (x)

The integer is converted to a Unicode character.

Ord (x)

Converts a single character to an integer value.

Hex (x)

Converts an integer to a hexadecimal string.

Oct (x)

Converts an integer into a eight-based string.

Python Learning note 02 python data type 2

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.