12 2019 档案

摘要:Python 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。 函数能提高应用的模块性,和代码的重复利用率。你已经知道Python提供了许多内建函数,比如print()。但你也可以自己创建函数,这被叫做用户自定义函数。 定义一个函数 你可以定义一个由自己想要功能的函数,以下是 阅读全文
posted @ 2019-12-30 22:01 二十四长夜明 阅读(205) 评论(0) 推荐(0)
摘要:Python3 字典 字典是另一种可变容器模型,且可存储任意类型对象。 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如下所示: d = {key1 : value1, key2 : value2 } 键必须是唯一的,但值 阅读全文
posted @ 2019-12-30 21:21 二十四长夜明 阅读(171) 评论(0) 推荐(0)
摘要:1、内建函数: (1)、sorted(iterable[,key][,reverse])排序 返回一个新的列表,默认升序 reverse是反转,当reverse是True时进行反转 (2)、chr(i)给一个一定范围的整数返回对应的字符 例: chr(97) ord(c)返回字符对应的整数 例:or 阅读全文
posted @ 2019-12-28 15:03 二十四长夜明 阅读(153) 评论(0) 推荐(0)
摘要:1、语法 [返回值 for 元素 in 可迭代对象 if 条件] 使用中括号[],内部是for循环,if条件语句可选 返回一个新列表 进阶: [expr for i in iterable for j in iterable2] 等价于: ret=[] for i initerable1: for 阅读全文
posted @ 2019-12-27 15:24 二十四长夜明 阅读(228) 评论(0) 推荐(0)
摘要:描述 random() 方法返回随机生成的一个实数,它在[0,1)范围内。 语法 以下是 random() 方法的语法: 1 import random 2 3 random.random() 注意:random()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用 阅读全文
posted @ 2019-12-17 10:44 二十四长夜明 阅读(672) 评论(0) 推荐(0)
摘要:1、datetime模块 对日期,时间,时间戳的处理 datetime类: 类方法: today()返回本地时区当前时间的datetime对象 now(tz=None)返回当前时间的datetime对象,时间到微秒,如果tz为None,返回和today()一样 utcnow()没有时区的当前时间 f 阅读全文
posted @ 2019-12-16 22:51 二十四长夜明 阅读(209) 评论(0) 推荐(0)
摘要:1、字典 1)、定义: key—value键值对的数据集合 可变的、无序的、key不重复 2)、格式 (1)、d=dict()或者d={} (2)、dict(**kwargs)使用name=value对初始化一个字典 (3)、dict(iterable,**kwarg) 使用可迭代对象或者name= 阅读全文
posted @ 2019-12-16 15:23 二十四长夜明 阅读(195) 评论(0) 推荐(0)
摘要:1、冒泡排序 a=[2,3,4,5,10,9,5,1,6,7] x=len(a) for i in range(x): flag=False for j in range(i+1,x): if a[i]>a[j]: temp=a[i] a[i]=a[j] a[j]=temp flag=True if 阅读全文
posted @ 2019-12-14 21:52 二十四长夜明 阅读(105) 评论(0) 推荐(0)
摘要:1、集合: 并集: union(*others) 返回和多个集合合并后的新的集合 ’ | ‘运算符重载:等同于union update(*others) 和多个集合合并,就地修改 ’ |= ‘等同update 例:a={1,2,3} b={2,3,4} c=a.union(b) #或者a|b >>> 阅读全文
posted @ 2019-12-13 17:54 二十四长夜明 阅读(198) 评论(0) 推荐(0)
摘要:1、转置矩阵的实现方法: #矩阵的转置 jz=[[1,2,3],[4,5,6],[7,8,9]] print(jz) for i,row in enumerate(jz): for j,col in enumerate(row): if i<j: jz[i][j],jz[j][i]=jz[j][i] 阅读全文
posted @ 2019-12-12 23:42 二十四长夜明 阅读(186) 评论(0) 推荐(0)
摘要:线性结构: 一、 1、线性结构:可以迭代,for ... in;len()可以获取长度;通过下标可以访问;可以切片 2、切片: 1)、通过索引访问线性结构的一段数据; sequence[start:stop]表示返回[start,stop],start默认为0,stop默认为末尾,支持负索引; 超过 阅读全文
posted @ 2019-12-11 17:36 二十四长夜明 阅读(156) 评论(0) 推荐(0)
摘要:bytes bytes是Python 3中特有的,Python 2 里不区分bytes和str。 Python 2中 >>> type(b'xxxxx') <type 'str'> >>> type('xxxxx') <type 'str'> Python 3中 >>> type(b'xxxxx') 阅读全文
posted @ 2019-12-11 16:06 二十四长夜明 阅读(529) 评论(0) 推荐(0)
摘要:字符串排版*: title():标题的每个单词都大写 capitalize():首个单词大写 center(width[,fillchar]):width打印宽度 fillchar填充的字符 zfil(width):width打印宽度,居右,左边用0填充 ljust(width[,fillchar] 阅读全文
posted @ 2019-12-11 00:25 二十四长夜明 阅读(169) 评论(0) 推荐(0)
摘要:1、math的一些常用函数 print(round(2.5)) #round()是四舍六入,五取偶;不是math下面的函数 print(round(1.2)) import math print(math.floor(2.5)) #向下取整 print(math.ceil(2.5)) #向上取整 p 阅读全文
posted @ 2019-12-10 15:53 二十四长夜明 阅读(304) 评论(0) 推荐(0)
摘要:代码1Fibonacci: a=1 b=1 x=int(input("输入你想求的Fibonacci数列的边界:")) print(a,end=' ') i=2 while i<=x: t=a+b a=b print(a,end=' ') b=t i+=1 结果:输入你想求的Fibonacci数列的 阅读全文
posted @ 2019-12-09 22:40 二十四长夜明 阅读(593) 评论(0) 推荐(0)
摘要:代码: 1、下面两个代码 的结果不太一样 for i in range(1,10): for j in range(1,i+1): print(str(j)+'*'+str(i)+'='+str(i*j),end=' ') print() 结果: for i in range(1,10): for 阅读全文
posted @ 2019-12-09 20:12 二十四长夜明 阅读(320) 评论(0) 推荐(0)