Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Python knowledge-nine data types
Python knowledge-nine data types
① Integer type

The abbreviation of integer accords with the concept of integer in mathematics. There are four representations of integer data, namely decimal, binary (starting with 0B or 0b), octal (starting with 0O or 0o) and hexadecimal (starting with 0X or 0x).

You can use Python's built-in function type () to test various data types.

② floating point type

Used to represent real numbers in mathematics, it is a data type with decimals. For example, 3. 14 and 1.0 are both floating-point types.

Floating-point type can be expressed in decimal or scientific notation.

③ String type

Python strings are sequences of characters enclosed in single quotation marks, double quotation marks and triple quotation marks.

For example: "python"

④ List type

A list is a collection of data, represented by square brackets [] and separated by commas.

For example: [1, 2, 3]

⑤ tuple type

A tuple is an immutable sequence type consisting of 0 or more elements. Tuples are represented by parentheses ().

For example: (1, 2, 3)

The difference between a tuple and a list is that the elements of a tuple cannot be modified.

6. Dictionary types

Dictionary is the only built-in mapping type in Python, which can be used to find relevant data through data.

A dictionary consists of two parts: keys and values, which are represented by curly braces. Elements are separated by commas, keys and values are separated by colons.

For example: {"Name": "Sun", "Age": 12}

⑦ Setting type

A collection consists of various types of elements, but there is no order between them and the elements will not be repeated.

For example: set ([ 1, 2,3])

8 compound type

Used in mathematics to represent complex numbers. For example: 1.5j

Pet-name ruby Boolean type

Boolean data has only two values: True and False.

If a Boolean value is operated numerically, True will be treated as integer 1, and False will be treated as integer 0.