Python basic sorting - range, xrange, array usage sorting

  •    The list in python is a built-in data type of python, the data types in the list do not have to be the same, and the types in the array must all be the same. The data type in the list stores the address of the data, which is simply the pointer, not the data , so it is too troublesome to save a list. For example, list1=[1,2,3,'a'] needs 4 Pointer and four data, increase storage and consume cpu.
  •       The array encapsulated in numpy has a very powerful function, and the same data type is stored in it.

1.array

create array

#创建一个array数据对象
a=np.array((1,2,3,4,5))# 参数是元组  
b=np.array([6,7,8,9,0])# 参数是list  
c=np.array([[1,2,3],[4,5,6]])# 参数二维数组  
print a,b,  
c.shape() 

 

2.range

The return object of range is a list.

The python range() function creates a list of integers and is typically used in for loops.

function syntax

range(start, stop[, step])

Parameter Description:

  • start: Counting starts from start. The default is to start from 0. For example range(5) is equivalent to range(0, 5);
  • end: Count up to the end of the end, but not including the end. For example: range(0, 5) is [0, 1, 2, 3, 4] not 5
  • step: the step size, the default is 1. For example: range(0, 5) is equivalent to range(0, 5, 1)

3.xrange

describe

The usage of the xrange() function is exactly the same as that of range , the difference is that it does not generate an array, but a generator.

grammar

xrange syntax:

xrange(stop)
xrange(start, stop[, step])

Parameter Description:

  • start: Counting starts from start. The default is to start from 0. For example range(5) is equivalent to range(0, 5);
  • end: Count up to the end of the end, but not including the end. For example: range(0, 5) is [0, 1, 2, 3, 4] not 5
  • step: the step size, the default is 1. For example: range(0, 5) is equivalent to range(0, 5, 1)

return value

return generator

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325845502&siteId=291194637