Introduction to Python common data types

1. Basic characteristics of the three variables

1, the seal

2, it is judged whether or not the value of the variable is equal to

3, it is determined whether the same variable id

2. The common data type classification

Digital type (int)

Type string (str)

List type (list)

Dictionary types (dict (dictinary))

Boolean type (bool)

Less common types: floating-point type (float), a collection of types (set)

3, a string (str)

3.1 to make: that name, loving

3.2 Definitions: string corresponds to a string of mutton. Character string and the string is strung up, wrapped in single quotes, or three double quotation marks a string of characters. Note that: three characters in quotation marks can newline, and characters in single or double quotation marks can not.

3.3 How to: + string only, and the logical comparison *

String concatenation, namely re-apply for a small space a copy of the two strings are then spliced. Instead you YY of the variable value in a small space inside the copy to another variable of a small space, and then stitching.

Note: If there are marks within a string, the string inside the quotation marks and wrapping string can not be the same.

Note: multiplication strings are only multiplied by the numbers.

Note: The string comparison size comparison of the ASCII code, the future will go into detail.

4. List Type (list)

4.1 Definitions: separated by commas any type of value within [].

4.2 as in: storing a plurality of values, such as a plurality of girlfriend, a plurality of hobbies.

4.3 How to use: deposit is not an end, is taking aim, we introduce the method list index value, bearing in mind the index number from zero.

The type of dictionary (dict)

5.1 Definitions: {} in the plurality of elements separated by commas, each element is key: value format, the format in which the value is an arbitrary data type, since the key has a function descriptive, it is usually a string key Types of.

5.2 role: a plurality of values ​​used to access, according to key: value of the stored-value mode, may not take the time to go to the index value by the key, key has a function of descriptive value. Store a variety of types of data and more data when you can use a dictionary.

5.3 How to use: the dictionary no longer dependent on the way the index value, but depends on the key, to obtain the value corresponding to the key value through the [key].

6. Boolean type (bool)

6.1 Definitions: True, False usually not directly quoted, required logic operation result obtained.

6.2 effect: Conditions for determination result

6.3 How

7. The output format in three ways

7.1 placeholder

7.2format format

7.3f-String formatting

Guess you like

Origin www.cnblogs.com/abdm-989/p/11270093.html