- 博客(31)
- 资源 (2)
- 收藏
- 关注
原创 python-返回值
函数用return语句返回值return后面的表达式的值就成为这次函数调用的返回值如果函数没有用return语句返回,这时函数返回的值就是none;如果return后面没有表达式,返回的值也是none。none是python中一个特殊的值。虽然它不表示任何数据,但任然具有重要的作用。求整数M和N区间内素数:def isprime(i): for k in range(2...
2019-11-21 15:17:23 159
原创 python-print()函数的完整表示
print(*object,sep="",end="\n",file=sys.stdout)object:输出参数,可变参数缺省值参数:sep="":输出分隔符end="\n":输出函数结束换行file=sys.stdout:输出到屏幕缺省...
2019-11-13 18:45:14 591
原创 python-函数参数
位置参数:求两点间距离import mathdef dis(x1,y1,x2,y2): print("x1={},y1={},x2={},y2={}".format(x1,y1,x2,y2)) return math.sqrt((x2-x1)**2+(y2-y1)**2)print(dis(1,2,3,4))output:x1=1,y1=2,x2=3,y2=42...
2019-11-13 18:38:43 144
原创 python-函数的定义与调用
求斐波那契数列的前n项:def febs(n): res=[1,1] for i in range(n-2): res.append(res[-2]+res[-1]) return resprint(febs(5))output: [1, 1, 2, 3, 5]函数必须先定义再调用:下面这个例子是错误的print(f(3))def f...
2019-11-11 21:42:32 187
原创 python-IO
读取txt文件:f = open("C:\python_learn\score.txt")for line in f: print(line)f.close
2019-11-11 20:03:35 73
原创 python-字典
创建字典:>>> d={'one':1,'two':2}>>> d{'one': 1, 'two': 2}字典的访问:>>> d['one']1在字典中添加键值:>>> d['three']=3>>> d{'one': 1, 'two': 2, 'three': 3}在字典中删除键...
2019-11-10 20:36:49 174
原创 python-集合
集合元素的唯一性:>>> s={1,2,3,4,5}>>> s.add(3)>>> s{1, 2, 3, 4, 5}>>> s.add(6)>>> s{1, 2, 3, 4, 5, 6}将列表转化为集合:>>> t=[1,2,3]>>> s=set(t...
2019-11-10 20:12:41 92
原创 python-异常
x = int(input())t = list(range(1,10,2))try: print(t[x])except: print('input is not a valid index')
2019-11-07 20:40:52 118
原创 python-求两数之间的素数
x,y = map(int,input().split())a=[]for i in range(min(x,y),max(x,y)+1): estimate = True for j in range(2,i): if i%j!=0: estimate=True else: estimate=F...
2019-11-07 19:44:38 4119 1
原创 python-map()函数
map() 会根据提供的函数对指定序列做映射。例如:x,y=map(int,input().split())print(x+y)>>>def square(x) : # 计算平方数... return x ** 2... >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方[1,...
2019-11-07 17:34:23 300
原创 python-随机模块
>>> t=[1,2,3,4,5,6,7,8,9]>>> import random>>> random.shuffle(t)>>> t[7, 2, 1, 5, 9, 3, 4, 6, 8]>>> t=['John','Kim','Mary','Sam']>>> rand...
2019-11-05 18:15:09 91
原创 python-列表操作方法
创建列表>>> a = 6>>> b = 8>>> t = [6,8]>>> t[6, 8]>>> t=[a,b]>>> t[6, 8]>>> t=[a+2,b-2]>>> t[8, 6]>>> s='this ...
2019-10-30 17:45:32 76
原创 python-字符串操作方法
字母操作capitalize() :将开头首字母改为大写,如果字符串开头非小写字母(如开头为大写字母、数字、空格等)则无效。>>> s='i am sam'>>> s.capitalize()'I am sam'>>> title():以空格、符号、数字等隔开的首字母大写>>> s='you are-welco...
2019-10-29 13:48:26 353
原创 python-内置函数
len()函数:返回字符串或列表的长度>>> a='1234567890'>>> len(a)10>>> b=[1,2,3,4,5,6]>>> len(b)6>>> min(a)'0'>>> max(a)'9'>>> min(b)1>&...
2019-10-29 11:51:26 94
原创 python-格式化输出
格式化输出摄氏度与华氏度的转化表:F=C∗1.8+32F=C*1.8+32F=C∗1.8+32lower,upper=input().split()lower,upper=int(lower),int(upper)c=range(lower,upper+1)for i in c: f=i*1.8+32 print('{0:.0f}\t{1:.2f}'.format(i,f...
2019-10-28 16:30:55 403
原创 python-列表推导式
列表推导式列表推导式(有称列表解析式)提供了一种简明扼要的方法来创建列表。它可以将循环和条件判断结合,从而避免语法冗长的代码,同时提高程序性能。基本格式:[expression for item in iterable]>>> n=[2*i for i in [1,2,3,4,5]]>>> n[2, 4, 6, 8, 10]当然也可以用ra...
2019-10-27 12:38:17 404
原创 python-列表
列表列表是python最常用的数据类型之一。由0个或多个元素组成,元素之间用逗号分开,整个列表被方括号所包裹。元素类型可以相同也可以不同。通过序号可以引用列表中的元素。支持加法、乘法、比较、索引、切片等操作:>>> [1,2,3]+['c',['java','python'],7][1, 2, 3, 'c', ['java', 'python'], 7]&g...
2019-10-27 09:54:43 78
原创 python-for语句
for 语句for i in [1,2,3,4]: print(i)for i in [1,2,3,4]: print(i,end=' ')
2019-10-27 09:01:44 73
原创 python-if语句
if语句判断一个数是奇数还是偶数:x=int(input())if x%2==0: print("even")else : print("odd")x=int(input())y=1 if x%2==1 else -1print(y)计算水费:为鼓励居民节约用水,自来水公司采取按用水量阶梯计费的方式。居民应交水费y(元)与月用水量x(吨)相关。当x不超过15吨...
2019-10-27 08:59:58 197
原创 python-赋值语句
赋值语句x=1y=2k=x+yprint(k)>>> x,y=4,9>>> print(x,y)4 9>>> a,b='34'>>> a'3'>>> b'4'>>> a=4>>> b=8>>> a,b=b,a>&g...
2019-10-27 08:59:01 313
原创 python-range()函数
range()函数range(start,end,step)start: 计数从start开始。默认是从0开始。例如: range(5)等价于range(0,5)stop: 计数到stop结束,但不包括stop。例如list(range(9,5))是[0,1,2,3,4],没有5。end: 步长,默认是1.例如:range(0,5)等价于range(0,5,1)>>...
2019-10-27 08:47:57 241
原创 python-转换内置函数
转换内置函数:bool()int()float()complex()str()ord()chr()bin()oct()hex()list()>>> list('abcd')['a', 'b', 'c', 'd']>>> int()0>>> int('02')2>>> int(' 3...
2019-10-26 01:24:19 111
原创 python-字符串
单引号、双引号、三引号:>>> "i'm sam""i'm sam">>> '"you are welcome", tom said''"you are welcome", tom said'>>> '''first row,secomd row.''''first row,\nsecomd row.'转义字符:\ 反斜杠符...
2019-10-25 17:23:46 125
原创 python-数字类型
整数不同进制表示二进制:前导符:0b 或 0B示例: 0b10 表示十进制的2八进制:前导符: 0o或0O示例: 0o10表示十进制的8十六进制:前导符: 0x或0X示例:0x10表示十进制的16科学计数法:1.23×1091.23×10^91.23×109 表示为 1.23e90.0000120.0000120.000012 表示为 1.2e−51.2e-51.2e−5...
2019-10-25 16:26:50 97
原创 manim-arrange_submobjects的应用及LaggedStart的应用
这是example_scenes.py中的代码class example(Scene): def construct(self): title = TextMobject("This is some \\LaTeX") basel = TexMobject( "\\sum_{n=1}^\\infty " "\...
2019-10-21 22:49:36 787 2
原创 manim-利用循环创建对象
class example(Scene): def construct(self): text_list=[] text_group=VGroup() for i in range(1,13): t=str(i) text=TextMobject(t) text.move...
2019-10-21 22:17:38 557 1
原创 manim-3D场景
标题class CameraPosition4(ThreeDScene): def construct(self): axes = ThreeDAxes() circle=Circle() self.set_camera_orientation(phi=80 * DEGREES,theta=20*DEGREES,gamma=30*DEGRE...
2019-10-19 22:04:04 2375 4
原创 manim-TextMobject 换行
manim-TextMobject 换行class example(Scene): def construct(self): text=TextMobject(r'This is the first raw. \\\ And this is the second raw.') self.play(Write(text),run_time=5) ...
2019-10-19 21:04:59 1031
数学超入门.[日]郡山彬.pdf
2019-07-12
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人