python基础第九天

时间:2022-06-06 14:38:43

  python基础学习

 范围查询:

>>> list(range(1, 11)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

******************************************************************
>>> L = [] >>> for x in range(1, 11): ... L.append(x * x) ... >>> L [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
****************************************************************************
>>> x = 'abc' >>> y = 123 >>> isinstance(x, str) True >>> isinstance(y, str) False
****************************************************************

斐波拉契数列

def fib(max): n, a, b = 0, 0, 1 while n < max: print(b) a, b = b, a + b n = n + 1 return 'done'
**************************************************************************
>>> f = abs >>> f(-10) 10
***************************************************************
 sorted([36, 5, -12, 9, -21]) 排序
sorted([36, 5, -12, 9, -21], key=abs) 按照绝对值

**************************************************************************