Overview of the basic data types Python

Overview of the basic data types Python

What is a data type?

Each programming language has its own data types, such as the most common numbers 1,2,3 ..... string 'Bob', 'age', '& D8' ..., these are the types of data of a certain kind.

Data types are defined in the same data structure and a set of assembly operations on a set of defined set of values ​​that a set of property values.

This section first describes the four kinds of types of data - number, string, boolean, list. In subsequent chapters will update all of the detail data types Python.

A digital

1, int (integer)

In the 64-bit operating system, an integer number of bits is 64 bits, the range of -2 63 is ~ 2 63 is -1 , i.e. -9223372036854775808 ~ 9223372036854775807.

2, long (Long)

Python does not limit the size of long integer values, but in fact the machine's memory is limited, so long integer value can not be infinite. (Pycharm run the following code in and see what the result will be)

Note: There is no longer a long in the Python3, only the int and float (will be described below)

a = 2**64
print(type(a))   # type()函数是用来查看数据类型的
b = 2**60
print(type(b))

3, float (float)

Decimal floating point is, as 1.2,3.476,6.423 and so on.

print(type(5.43))

Second, the string

In Python, add a character quotes are considered strings. E.g:

name = 'kwan'     # 单引号
age = "21"        # 双引号
sex = '''男'''     # 三个单引号
like = """学习"""  # 三个双引号                   这些都是定义字符串的方法

Above variables are of type string, these methods there is no difference, then why should Python To set up such a variety of methods defined string it? Consider the following line of code:

say1 = "Today is ncie, and I'm very happy." 
print(say1)         #   不会报错

say2 = 'Today is ncie, and I'm very happy.'
print(say2)         #   会报错

The above code tells us, when you need to use quotation marks as the content string in the string, this time on the need to use different quotes nested with use. (Here involves the escape character content, it will be dedicated to a follow-up blog post about the characters escaped)

String splicing

Digital subtraction multiplication and division and other operations can be carried out, string it? Only the string "addition" and "multiplication" operation.

Note: The string of splicing (addition) is carried out only in the case of both sides of the string, it can not be joined with other data types.

Note: The multiplication of the string, and the string can only multiply the number and the figure must be plastic.

Third, the Boolean (bool)

Only two Boolean values, a is True , a is False , determining a Boolean logic type is mainly used.

Fourth, the list (list)

Suppose now that the name of the class you need to survive all this time if the string type will be very convenient, because you can not select the specified name (although the method of cutting the string can do, but a lot of trouble) at the time of print, this time we need to use the list.

List element position is marked by index, from index 0.

Element name kwan kobe james haha alex
Subscript (index) 0 1 2 3 4

Additions and deletions to the list of elements of the investigation changed

1, added

① Insert

② add

2, remove elements

Note: remove method deletes the specified element from the left first began to find if there are multiple elements specified deleted in the list, only the first one from the left to delete the specified element found begin.

3. Find

① find elements by index: "four, list (list)" table below is to find the elements by index.

② confirmed by elemental index

Note: index method will find a specified element from the left, if there are multiple elements specified in the list, you only get the index value of a specified element from the left found.

4, change

Directly to the corresponding element of the index can be reassigned.

5, it is determined whether the elements in the list

It can be used in the determination method, specifically using the method shown below.

Guess you like

Origin www.cnblogs.com/Kwan-C/p/11426275.html