苹果手机的10次方怎么打12怎样输入10的8次方

   暑假的时间是比较长的,那么合理的安排好自己的时间,才能够更加充实,别忘了做好暑假作业哦。下面是由出国留学网小编为大家整理的“初一数学暑假作业答案2021”,仅供参考,欢迎大家阅读。  初一数学暑假作业答案2021  (一)  1.气球下降6米2.0,03.-3,3,34.5,-4,05.>,<,=6.0  7.368.略9.B10.B11.C12.B13.正整数:10,+68;负整数:-20;正分数:0.22,+9.78,0.3,+;负分数:-2.5,;正有理数:10,0.22,+9.78,+68,0.3,  +;负有理数:-2.5,-2014.数轴略,-3<-|-2|<0<-2.5的相反数<4  15.(1)4,6,-4(2)略16.2009  (二)  1.(1)-6(2)-42.-9+2-7-5+43.54.-105.A6.D7.A  8.(1)-30(2)-3.5(3)19(4)-29.±2,±1410.(1)9  (2)-498,4,50611.(1)略(2)π-3.14(3)  (三)  1.(1)18(2)28(3)-72(4)02.略3.04.D5.D6.C  7.(1)2(2)2(3)6(4)08.略9.(1)<,<,>,>,>  (2)nn+1<(n+1)n(0(n+1)n(n>2)(3)>  (四)  1.-2,2,42.2,2,-43.04.千,35.D6.C7.C8.D  9.(1)809.79(2)0.083(3)5480万(4)9.7×10710.(1)-9(2)16  (3)(4)(5)72(6)11.略  (五)  1.,±6,±22.13,-3.略4.55.D6.B7.C8.D  9.(1)±4(2)-10.0.49111.=2秒,19.6÷340≈0.057秒,最后的结论由学生定12.略  (六)  1.1.3m2.3.略4.6x-4y,-a-b+c5.a+d=b+c6.-117.B  8.C9.B10.(1)0(2)17x-111.-612.(1)y=20.2x(2)161.6元  13.(1)计时制:3x,包月制:50+1.2x(2)3x=3×30=90元,50+1.2x=50+1.2×30=86元,所以包月制合算  (七)  1.x=22.略3.-14.-15.46.C7.B8.D  9.(1)x=(2)x=11(3)x=0(4)x=10.(1)3x=x+4(2)x+3=x-2  (3)-x=|x|-611.(1)五个数的和是16的5倍(2)5x(3)5x=2010,得x=402,而402排在第一列位置,所以五个数的和不能等于2010  (八)  1.3x=x+102.-73.34.1.15.B6.A7.C8.C9.x=5  10.调往甲处17人,调往乙处3人11.2250元12.略13.(1)一道正门和一道侧门每分钟分别可以通过120名和80名学生(2)符合安全规定  (九)  1.条形统计...
查看全文
 
  在暑假里,我们除了玩耍外,也要按时完成暑假作业。朋友,以下是由出国留学网小编为大家精心整理的“2018七年级数学暑假作业答案”,仅供参考,欢迎大家阅读。  2018七年级数学暑假作业答案  【第一天】  1.-0.1米2.3分之5,±13.34.±2,±1,05.1.5×10的8次方6.C7.B8.D9.略10.(1)有,是1;没有。(2)没有;有,是-111.(1)2,2;2,1。(2)m-n的绝对值12.8913.略  【第二天】  1.B2.A3.D4.答案不,如-3的绝对值+2=55.(1)在点O右侧6厘米处(2)5cm/min6.略7.D8.6174  【第三天】  1.B2.D3.B4.略5.16.2011×(1-2分之1)(1-3分之1)(1-4分之1)=4分之2011  2011×(1-2分之1)(1-3分之1)(1-4分之1)……(1-2011分之1)=17.4.19×10的7次方KB  1.02×10的5次方本  【第四天】  1.C2.C3.C4.C5.B6.略7.(1)5/6(2)n/n+1(3)178.(a)5(b)7  【第五天】  1.D2.B3.C4.D5.a≤06.略7.如1.212212221…8.a<0,b=3,c=0或1,∴b>c>a9.面积是2,边长是根号2。图略10.D  【第六天】  1.√×××2.C3.834.(1)w/h2(2)P=65/1.752=21.22,∴王老师健康5.略6.107.9800+200n9850+200n差50元在B公司有利  【第七天】  1.B2.D3.C4.C5.略6.略7.(1)解:设共有n个数∵2011=2n-1,∴n=1006又∵2011÷16=125……11∴2011在第125行第6列(2)设左上角第一个数是m,则m+m+2+m+16+m+18=1416∴m=345∴这四个数是345,347,361,3638.至少会有一个是整数  【第八天】  1.B2.A3.A4.D5.略6.略7.解:设购买的香蕉是x千克,则购买苹果(70-x)千克。①若两种水果的质量都在30~50千克,则3.5x+3.5(70-x)=259  方程无解,舍去②若香蕉的质量不超过30千克,苹果的质量在30~50千克之间,则4x+3.5(70-x)=259,x=28③若香蕉的质量不超过30千克,苹果的质量在50千克以上4x+3(70-x)=259,x=49,不合题意,舍去。答:购买了香蕉28千克,苹果4千克。8.①x=1/3②x=-1  【第九天】  1.5/7  2.48  3.40-x=2/3×(30+x)  4.(x+4)(x+2)-x(x+2)=24  5.5x+4x+3x+5x=34,  66.132  7.(1)设购进甲种x件,则购进乙种(80-x)件,则10x+(80-x)×30=1600,x=40(2)甲38件,乙42件;或甲39件,乙41件;或甲40件,乙4...
查看全文
 
  朋友,在暑假里玩得怎样呢?做完暑假作业的你是不是打算核对一下答案呢?以下是由出国留学网小编为大家精心带来的“初一数学暑假作业答案2018”,仅供参考,欢迎大家阅读,希望能够对大家有所帮助哦。  初一数学暑假作业答案2018  第一天  1.-0.1米 2.3分之5,±1 3.3 4.±2,±1,0 5.1.5×10的8次方 6.C 7.B 8.D 9.略 10.(1)有,是1;没有。(2)没有;有,是-1 11.(1)2,2;2,1。(2)m-n的绝对值 12.89 13.略  第二天  1.B 2.A 3.D 4.答案不唯一,如-3的绝对值+2=5 5.(1)在点O右侧6厘米处(2)5cm/min 6.略 7.D 8.6174  第三天  1.B 2.D 3.B 4.略 5.1 6.20xx×(1-2分之1)(1-3分之1)(1-4分之1)=4分之20xx  20xx×(1-2分之1)(1-3分之1)(1-4分之1)……(1-20xx分之1)=1 7.4.19×10的7次方KB  1.02×10的5次方本  第四天  1.C 2.C 3.C 4.C 5.B 6.略 7.(1)5/6 (2)n/n+1 (3)17 8.(a)5 (b)7  第五天  1.D 2.B 3.C 4.D 5.a≤0 6.略 7.如1.212212221… 8.a<0,b=3,c=0或1,∴b>c>a 9.面积是2,边长是根号2。图略 10.D  第六天  1.√××× 2.C 3.83 4.(1)w/h (2)P=65/1.75=21.22,∴王老师健康 5.略 6.10 7.9800+200n 9850+200n 差50元 在B公司有利  第七天  1.B 2.D 3.C 4.C 5.略 6.略 7.(1)解:设共有n个数 ∵20xx=2n-1,∴n=1006 又∵20xx÷16=125……11 ∴20xx在第125行第6列 (2)设左上角第一个数是m,则m+m+2+m+16+m+18=1416 ∴m=345 ∴这四个数是345,347,361,363 8.至少会有一个是整数  第八天  1.B 2 .A 3.A 4.D 5.略 6.略 7.解:设购买的香蕉是x千克,则购买苹果(70-x)千克。①若两种水果的质量都在30~50千克,则3.5x+3.5(70-x)=259  方程无解,舍去②若香蕉的质量不超过30千克,苹果的质量在30~50千克之间,则4x+3.5(70-x)=259,x=28 ③若香蕉的质量不超过30千克,苹果的质量在50千克以上4x+3(70-x)=259,x=49,不合题意,舍去。答:购买了香蕉28千克,苹果4千克。  8.①x=1/3 ②x=-1  推荐阅读:  2018初一语文暑假作业答案  
查看全文
 
  2016初一数学暑假作业答案  暑假过得开心吗?一定不要忘记还有作业要做哦,如果已经完成了,就来看看小编给你的答案吧。  1.1 整式  1.(1)c、d、f;(2)a、b、g、h;(3)a、b;(4)g;(5)e、i;2. ;3. ; 4.四,四,- ab2c,- ,25 ;5.1,2;6. a3b2c;7.3x3-2x2-x;8. ;9.d;10.a; 11.b-;12.d ;13.c;14. ;15.a= ;16.n= ;四.-1.  1.2 整式的加减  1.-xy+2x2y2; 2.2x2+2x2y; 3.3; 4.a2-a+6; 5.99c-99a; 6.6x2y+3x2y2-14y3; 7. ; 8. ; 9.d; 10.d; 11.d; 12.b; 13.c; 14.c; 15.b; 16.d; 17.c;18.解:原式= ,当a=-2,x=3时, 原式=1.  19. 解:x=5,m=0,y=2,原式=5.20.(8a-5b)-[(3a-b)- ]= ,当a=10,b=8时,上车乘客是29人.21. 解:由 ,得xy=3(x+y),原式= .  22. 解:(1)1,5,9,即后一个比前一个多4正方形.  (2)17,37,1+4(n-1).  四.解:3幅图中,需要的绳子分别为4a+4b+8c,4a+4b+4c,6a+6b+4c,  所以(2)中的用绳最短,(3)中的用绳最长.  1.3 同底数幂的乘法  1. , ;2.2x5,(x+y)7 ;3.106;4.3;5.7,12,15,3 ;6.10;7.d ;8.b-; 9.d;10.d; 11.b;12.(1)-(x-y)10 ;(2)-(a-b-c)6;(3)2x5 ;(4)-xm  13.解:9.6×106×1.3×108≈1.2×1015(kg).  14.(1)① ,② .  (2)①x+3=2x+1,x=2 ②x+6=2x,x=6.  15.-8x7y8 ;16.15x=-9,x=- .  四.105.毛  1.4 幂的乘方与积的乘方  1. , ;2. ;3.4 ;4. ;5. ; 6.1,-1;7.6,108; 8.37;9.a、d;10.a、c;11.b;12.d ;13.a ;14.;15.a;16.b.17.(1)0;(2) ;(3)0.  18.(1)241 (2)540019. ,而 , 故 .20.-7;  21.原式= ,  另知的末位数与33的末位数字相同都是7,而 的末位数字为5,  ∴原式的末位数字为15-7=8.  四.400.毛  1.5 同底数幂的除法  1.-x3,x ;2.2.04×10-4kg;3.≠2;4.26;5.(m-n)6;6.100 ;7. ;8.2;9.3-,2,2; 10.2m=n;11.b; 12.;13.c;14....
查看全文
一、
Python 基础 62 例1
十转二将十进制转换为二进制:>>> bin(10)
'0b1010'2 十转八十进制转换为八进制:>>> oct(9)
'0o11'3 十转十六十进制转换为十六进制:>>> hex(15)
'0xf'4
字符串转字节字符串转换为字节类型>>> s = "apple"
>>> bytes(s,encoding='utf-8')
b'apple'5 转为字符串字符类型、数值型等转换为字符串类型>>> i = 100
>>> str(i)
'100'6 十转ASCII十进制整数对应的 ASCII 字符>>> chr(65)
'A'7 ASCII转十ASCII字符对应的十进制数>>> ord('A')
658 转为字典创建数据字典的几种方法>>> dict()
{}
>>> dict(a='a',b='b')
{'a': 'a', 'b': 'b'}
>>> dict(zip(['a','b'],[1,2]))
{'a': 1, 'b': 2}
>>> dict([('a',1),('b',2)])
{'a': 1, 'b': 2}9 转为浮点类型整数或数值型字符串转换为浮点数>>> float(3)
3.0如果不能转化为浮点数,则会报ValueError:>>> float('a')
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
float('a')
ValueError: could not convert string to float: 'a'10
转为整型int(x, base =10)x 可能为字符串或数值,将 x 转换为整数。如果参数是字符串,那么它可能包含符号和小数点。如果超出普通整数的表示范围,一个长整数被返回。>>> int('12',16)
1811
转为集合返回一个 set 对象,集合内不允许有重复元素:>>> a = [1,4,2,3,1]
>>> set(a)
{1, 2, 3, 4}12 转为切片class slice(start, stop[, step])返回一个由 range(start, stop, step) 指定索引集的 slice 对象,代码可读性变好。>>> a = [1,4,2,3,1]
>>> my_slice = slice(0,5,2)
>>> a[my_slice]
[1, 2, 1]13 转元组tuple() 将对象转为一个不可变的序列类型>>> a=[1,3,5]
>>> a.append(7)
>>> a
[1, 3, 5, 7]
#禁止a增删元素,只需转为元组
>>> t=tuple(a)
>>> t
(1, 3, 5, 7)14 转冻结集合创建不可修改的集合:>>> a = frozenset([1,1,3,2,3])
>>> a # a 无 pop,append,insert等方法
frozenset({1, 2, 3})15 商和余数分别取商和余数>>> divmod(10,3)
(3, 1)16 幂和余同时做pow 三个参数都给出表示先幂运算再取余:>>> pow(3, 2, 4)
117 四舍五入四舍五入,ndigits代表小数点后保留几位:>>> round(10.045, 2)
10.04
>>> round(10.046, 2)
10.0518 查看变量所占字节数>>> import sys
>>> a = {'a':1,'b':2.0}
>>> sys.getsizeof(a) # 变量占用字节数
24019 门牌号返回对象的内存地址>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> id(xiaoming)
228193073908020 排序函数排序:>>> a = [1,4,2,3,1]
#降序
>>> sorted(a,reverse=True)
[4, 3, 2, 1, 1]
>>> a = [{'name':'xiaoming','age':18,'gender':'male'},
{'name':'xiaohong','age':20,'gender':'female'}]
#按 age升序
>>> sorted(a,key=lambda x: x['age'],reverse=False)
[{'name': 'xiaoming', 'age': 18, 'gender': 'male'},
{'name': 'xiaohong', 'age': 20, 'gender': 'female'}]21 求和函数求和:>>> a = [1,4,2,3,1]
>>> sum(a)
11
#求和初始值为1
>>> sum(a,1)
1222 计算表达式计算字符串型表达式的值>>> s = "1 + 3 +5"
>>> eval(s)
9
>>> eval('[1,3,5]*3')
[1, 3, 5, 1, 3, 5, 1, 3, 5]23 真假>>> bool(0)
False
>>> bool(False)
False
>>> bool(None)
False
>>> bool([])
False
>>> bool([False])
True
>>> bool([0,0,0])
True24 都为真如果可迭代对象的所有元素都为真,那么返回 True,否则返回False#有0,所以不是所有元素都为真
>>> all([1,0,3,6])
False#所有元素都为真
>>> all([1,2,3])
True25 至少一个为真接受一个可迭代对象,如果可迭代对象里至少有一个元素为真,那么返回True,否则返回False# 没有一个元素为真
>>> any([0,0,0,[]])
False# 至少一个元素为真
>>> any([0,0,1])
True26 获取用户输入获取用户输入内容>>> input()
I'm typing
"I'm typing "27 print 用法>>> lst = [1,3,5]
# f 打印
>>> print(f'lst: {lst}')
lst: [1, 3, 5]
# format 打印
>>> print('lst:{}'.format(lst))
lst:[1, 3, 5]28 字符串格式化格式化字符串常见用法>>> print("i am {0},age {1}".format("tom",18))
i am tom,age 18
>>> print("{:.2f}".format(3.1415926)) # 保留小数点后两位
3.14
>>> print("{:+.2f}".format(-1)) # 带符号保留小数点后两位
-1.00
>>> print("{:.0f}".format(2.718)) # 不带小数位
3
>>> print("{:0>3d}".format(5)) # 整数补零,填充左边, 宽度为3
005
>>> print("{:,}".format(10241024)) # 以逗号分隔的数字格式
10,241,024
>>> print("{:.2%}".format(0.718)) # 百分比格式
71.80%
>>> print("{:.2e}".format(10241024)) # 指数记法
1.02e+0729 返回对象哈希值返回对象的哈希值。值得注意,自定义的实例都可哈希:>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> hash(xiaoming)
-9223371894234104688list, dict, set等可变对象都不可哈希(unhashable):>>> hash([1,3,5])
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
hash([1,3,5])
TypeError: unhashable type: 'list'30 打开文件返回文件对象>>> import os
>>> os.chdir('D:/source/dataset')
>>> os.listdir()
['drinksbycountry.csv', 'IMDB-Movie-Data.csv', 'movietweetings',
'titanic_eda_data.csv', 'titanic_train_data.csv']
>>> o = open('drinksbycountry.csv',mode='r',encoding='utf-8')
>>> o.read()
"country,beer_servings,spirit_servings,wine_servings,total_litres_of_pur
e_alcohol,continent\nAfghanistan,0,0,0,0.0,Asia\nAlbania,89,132,54,4.9,"mode 取值表:读取(默认)31 查看对象类型class type(name, bases, dict)传入参数,返回 object 类型:>>> type({4,6,1})
<class 'set'>
>>> type({'a':[1,2,3],'b':[4,5,6]})
<class 'dict'>
>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> type(Student('1','xiaoming'))
<class '__main__.Student'>32
两种创建属性方法返回 property 属性,典型的用法:>>> class C:
def __init__(self):
self._x = None
def getx(self):
return self._x
def setx(self, value):
self._x = value
def delx(self):
del self._x
# 使用property类创建 property 属性
x = property(getx, setx, delx, "I'm the 'x' property.")使用 C 类:>>> C().x=1
>>> c=C()
# 属性x赋值
>>> c.x=1
# 拿值
>>> c.getx()
1
# 删除属性x
>>> c.delx()
# 再拿报错
>>> c.getx()
Traceback (most recent call last):
File "<pyshell#118>", line 1, in <module>
c.getx()
File "<pyshell#112>", line 5, in getx
return self._x
AttributeError: 'C' object has no attribute '_x'
# 再属性赋值
>>> c.x=1
>>> c.setx(1)
>>> c.getx()
1使用@property装饰器,实现与上完全一样的效果:class C:
def __init__(self):
self._x = None
@property
def x(self):
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x33 是否可调用判断对象是否可被调用,能被调用的对象是一个callable 对象。>>> callable(str)
True
>>> callable(int)
TrueStudent 对象实例目前不可调用:>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student(id='1',name='xiaoming')
>>> callable(xiaoming)
False如果 xiaoming能被调用 , 需要重写Student类的__call__方法:>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name此时调用 xiaoming():>>> xiaoming = Student('001','xiaoming')
>>> xiaoming()
I can be called
my name is xiaoming34 动态删除属性删除对象的属性>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> delattr(xiaoming,'id')
>>> hasattr(xiaoming,'id')
False35 动态获取对象属性获取对象的属性>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> getattr(xiaoming,'name') # 获取name的属性值
'xiaoming'36 对象是否有某个属性>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> getattr(xiaoming,'name')# 判断 xiaoming有无 name属性
'xiaoming'
>>> hasattr(xiaoming,'name')
True
>>> hasattr(xiaoming,'address')
False37 isinstance判断object是否为classinfo的实例,是返回true>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> isinstance(xiaoming,Student)
True38 父子关系鉴定>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> class Undergraduate(Student):
pass
# 判断 Undergraduate 类是否为 Student 的子类
>>> issubclass(Undergraduate,Student)
True第二个参数可为元组:>>> issubclass(int,(int,float))
True39 所有对象之根object 是所有类的基类>>> isinstance(1,object)
True
>>> isinstance([],object)
True40 一键查看对象所有方法不带参数时返回当前范围内的变量、方法和定义的类型列表;带参数时返回参数的属性,方法列表。>>> class Student():
def __init__(self,id,name):
self.id = id
self.name = name
>>> xiaoming = Student('001','xiaoming')
>>> dir(xiaoming)
['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'id', 'name']41 枚举对象Python 的枚举对象>>> s = ["a","b","c"]
>>> for i,v in enumerate(s):
print(i,v)
0 a
1 b
2 c42 创建迭代器>>> class TestIter():
def __init__(self,lst):
self.lst = lst
# 重写可迭代协议__iter__
def __iter__(self):
print('__iter__ is called')
return iter(self.lst)迭代 TestIter 类:>>> t = TestIter()
>>> t = TestIter([1,3,5,7,9])
>>> for e in t:
print(e)
__iter__ is called
1
3
5
7
943 创建range迭代器range(stop)range(start, stop[,step])生成一个不可变序列的迭代器:>>> t = range(11)
>>> t = range(0,11,2)
>>> for e in t:
print(e)
0
2
4
6
8
1044 反向>>> rev = reversed([1,4,2,3,1])
>>> for i in rev:
print(i)
1
3
2
4
145 打包聚合各个可迭代对象的迭代器:>>> x = [3,2,1]
>>> y = [4,5,6]
>>> list(zip(y,x))
[(4, 3), (5, 2), (6, 1)]
>>> for i,j in zip(y,x):
print(i,j)
4 3
5 2
6 146 过滤器函数通过 lambda 表达式设定过滤条件,保留 lambda 表达式为True的元素:>>> fil = filter(lambda x: x>10,[1,11,2,45,7,6,13])
>>> for e in fil:
print(e)
11
45
1347 链式比较>>> i = 3
>>> 1 < i < 3
False
>>> 1 < i <=3
True48
链式操作>>> from operator import (add, sub)
>>> def add_or_sub(a, b, oper):
return (add if oper == '+' else sub)(a, b)
>>> add_or_sub(1, 2, '-')
-149 split 分割**>>> 'i love python'.split(' ')
['i', 'love', 'python']50 replace 替换>>> 'i\tlove\tpython'.replace('\t',',')
'i,love,python'51 反转字符串>>> st="python"
>>> ''.join(reversed(st))
'nohtyp'52 使用time模块打印当前时间# 导入time模块
>>> import time
# 打印当前时间,返回浮点数
>>> seconds = time.time()
>>> seconds
1588858156.614625553 浮点数转时间结构体# 浮点数转时间结构体
>>> local_time = time.localtime(seconds)
>>> local_time
time.struct_time(tm_year=2020, tm_mon=5, tm_mday=7, tm_hour=21, tm_min=29, tm_sec=16, tm_wday=3, tm_yday=128, tm_isdst=0)tm_year: 年tm_mon: 月tm_mday: 日tm_hour: 小时tm_min:分tm_sec: 分tm_sec: 秒tm_wday: 一周中索引([0,6], 周一的索引:0)tm_yday: 一年中索引([1,366])tm_isdst: 1 if summer time is in effect, 0 if not, and -1 if unknown54 时间结构体转时间字符串# 时间结构体转时间字符串
>>> str_time = time.asctime(local_time)
>>> str_time
'Thu May
7 21:29:16 2020'55 时间结构体转指定格式时间字符串# 时间结构体转指定格式的时间字符串
>>> format_time = time.strftime('%Y.%m.%d %H:%M:%S',local_time)
>>> format_time
'2020.05.07 21:29:16'56 时间字符串转时间结构体# 时间字符串转时间结构体
>>> time.strptime(format_time,'%Y.%m.%d %H:%M:%S')
time.struct_time(tm_year=2020, tm_mon=5, tm_mday=7, tm_hour=21, tm_min=29, tm_sec=16, tm_wday=3, tm_yday=128, tm_isdst=-1)57 年的日历图>>> import calendar
>>> from datetime import date
>>> mydate=date.today()
>>> calendar.calendar(2020)结果:
2020
January
February
March
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
1
2
3
4
5
1
2
1
6
7
8
9 10 11 12
3
4
5
6
7
8
9
2
3
4
5
6
7
8
13 14 15 16 17 18 19
10 11 12 13 14 15 16
9 10 11 12 13 14 15
20 21 22 23 24 25 26
17 18 19 20 21 22 23
16 17 18 19 20 21 22
27 28 29 30 31
24 25 26 27 28 29
23 24 25 26 27 28 29
30 31
April
May
June
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
1
2
3
4
5
1
2
3
1
2
3
4
5
6
7
6
7
8
9 10 11 12
4
5
6
7
8
9 10
8
9 10 11 12 13 14
13 14 15 16 17 18 19
11 12 13 14 15 16 17
15 16 17 18 19 20 21
20 21 22 23 24 25 26
18 19 20 21 22 23 24
22 23 24 25 26 27 28
27 28 29 30
25 26 27 28 29 30 31
29 30
July
August
September
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
1
2
3
4
5
1
2
1
2
3
4
5
6
6
7
8
9 10 11 12
3
4
5
6
7
8
9
7
8
9 10 11 12 13
13 14 15 16 17 18 19
10 11 12 13 14 15 16
14 15 16 17 18 19 20
20 21 22 23 24 25 26
17 18 19 20 21 22 23
21 22 23 24 25 26 27
27 28 29 30 31
24 25 26 27 28 29 30
28 29 30
31
October
November
December
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
Mo Tu We Th Fr Sa Su
1
2
3
4
1
1
2
3
4
5
6
5
6
7
8
9 10 11
2
3
4
5
6
7
8
7
8
9 10 11 12 13
12 13 14 15 16 17 18
9 10 11 12 13 14 15
14 15 16 17 18 19 20
19 20 21 22 23 24 25
16 17 18 19 20 21 22
21 22 23 24 25 26 27
26 27 28 29 30 31
23 24 25 26 27 28 29
28 29 30 31
3058 月的日历图>>> import calendar
>>> from datetime import date
>>> mydate = date.today()
>>> calendar.month(mydate.year, mydate.month)结果:
May 2020
Mo Tu We Th Fr Sa Su
1
2
3
4
5
6
7
8
9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 3159 判断是否为闰年>>> import calendar
>>> from datetime import date
>>> mydate = date.today()
>>> is_leap = calendar.isleap(mydate.year)
>>> ("{}是闰年" if is_leap else "{}不是闰年\n").format(mydate.year)
'2020是闰年'60 with 读写文件读文件:>> import os
>>> os.chdir('D:/source/dataset')
>>> os.listdir()
['drinksbycountry.csv', 'IMDB-Movie-Data.csv', 'movietweetings', 'test.csv', 'titanic_eda_data.csv', 'titanic_train_data.csv', 'train.csv']
# 读文件
>>> with open('drinksbycountry.csv',mode='r',encoding='utf-8') as f:
o = f.read()
print(o)写文件:# 写文件
>>> with open('new_file.txt',mode='w',encoding='utf-8') as f:
w = f.write('I love python\n It\'s so simple')
os.listdir()
['drinksbycountry.csv', 'IMDB-Movie-Data.csv', 'movietweetings', 'new_file.txt', 'test.csv', 'titanic_eda_data.csv', 'titanic_train_data.csv', 'train.csv']
>>> with open('new_file.txt',mode='r',encoding='utf-8') as f:
o = f.read()
print(o)
I love python
It's so simple61 提取后缀名>>> import os
>>> os.path.splitext('D:/source/dataset/new_file.txt')
('D:/source/dataset/new_file', '.txt') #[1]:后缀名62 提取完整文件名>>> import os
>>> os.path.split('D:/source/dataset/new_file.txt')
('D:/source/dataset', 'new_file.txt')二、 Python 核心 12 例63 斐波那契数列前n项>>> def fibonacci(n):
a, b = 1, 1
for _ in range(n):
yield a
a, b = b, a+b # 注意这种赋值
>>> for fib in fibonacci(10):
print(fib)
1
1
2
3
5
8
13
21
34
5564 list 等分 n 组>>> from math import ceil
>>> def divide_iter(lst, n):
if n <= 0:
yield lst
return
i, div = 0, ceil(len(lst) / n)
while i < n:
yield lst[i * div: (i + 1) * div]
i += 1
>>> for group in divide_iter([1,2,3,4,5],2):
print(group)
[1, 2, 3]
[4, 5]65 yield 解释有好几位同学问我,生成器到底该怎么理解。在这里我总结几句话,看看是否对不理解生成器的朋友有帮助。生成器首先是一个 “特殊的” return ,遇到 yield 立即中断返回。但是,又与 return 不同,yield 后下一次执行会进入到yield 的下一句代码,而不像 return 下一次执行还是从函数体的第一句开始执行。可能还是没说清,那就用图解释一下:第一次 yield 返回 1第二次迭代,直接到位置 2 这句代码:然后再走 for ,再 yield ,重复下去,直到for结束。以上就是理解 yield 的重点一个方面。66 装饰器66.1 定义装饰器time 模块大家比较清楚,第一个导入 wraps 函数(装饰器)为确保被装饰的函数名称等属性不发生改变用的,这点现在不清楚也问题不大,实践一下就知道了。from functools import wraps
import time定义一个装饰器:print_info,装饰器函数入参要求为函数,返回值要求也为函数。如下,入参为函数 f, 返回参数 info 也为函数,满足要求。def print_info(f):
"""
@para: f, 入参函数名称
"""
@wraps(f) # 确保函数f名称等属性不发生改变
def info():
print('正在调用函数名称为: %s ' % (f.__name__,))
t1 = time.time()
f()
t2 = time.time()
delta = (t2 - t1)
print('%s 函数执行时长为:%f s' % (f.__name__,delta))
return info66.2使用装饰器使用 print_info 装饰器,分别修饰 f1, f2 函数。软件工程要求尽量一次定义,多次被复用。@print_info
def f1():
time.sleep(1.0)
@print_info
def f2():
time.sleep(2.0)66.3 使用装饰后的函数使用 f1, f2 函数:f1()
f2()
# 输出信息如下:
# 正在调用函数名称为:f1
# f1 函数执行时长为:1.000000 s
# 正在调用函数名称为:f2
# f2 函数执行时长为:2.000000 s67 迭代器案例一个类如何成为迭代器类型,请看官方PEP说明:即必须实现两个方法(或者叫两种协议):__iter__ , __next__下面编写一个迭代器类:class YourRange():
def __init__(self, start, end):
self.value = start
self.end = end
# 成为迭代器类型的关键协议
def __iter__(self):
return self
# 当前迭代器状态(位置)的下一个位置
def __next__(self):
if self.value >= self.end:
raise StopIteration
cur = self.value
self.value += 1
return cur使用这个迭代器:yr = YourRange(5, 12)
for e in yr:
print(e)迭代器实现__iter__ 协议,它就能在 for 上迭代,参考官网PEP解释:文章最后提个问题,如果此时运行:next(yr)会输出 5, 还是报错?如果 yr 是 list,for 遍历后,再 next(iter(yr)) 又会输出什么?如果能分清这些问题,恭喜你,已经真正理解迭代器迭代和容器遍历的区别。如果你还拿不准,欢迎交流。下面使用 4 种常见的绘图库绘制柱状图和折线图,使用尽可能最少的代码绘制,快速入门这些库是本文的写作目的。68 matplotlib导入包:import matplotlib
matplotlib.__version__
# '2.2.2'
import matplotlib.pyplot as plt绘图代码:import matplotlib.pyplot as plt
plt.plot([0, 1, 2, 3, 4, 5],
[1.5, 1, -1.3, 0.7, 0.8, 0.9]
,c='red')
plt.bar([0, 1, 2, 3, 4, 5],
[2, 0.5, 0.7, -1.2, 0.3, 0.4]
)
plt.show()69 seaborn导入包:import seaborn as sns
sns.__version__ # '0.8.0'绘制图:sns.barplot([0, 1, 2, 3, 4, 5],
[1.5, 1, -1.3, 0.7, 0.8, 0.9]
)
sns.pointplot([0, 1, 2, 3, 4, 5],
[2, 0.5, 0.7, -1.2, 0.3, 0.4]
)
plt.show()70 plotly 绘图导入包:import plotly
plotly.__version__ # '2.0.11'绘制图(自动打开html):import plotly.graph_objs as go
import plotly.offline as offline
pyplt = offline.plot
sca = go.Scatter(x=[0, 1, 2, 3, 4, 5],
y=[1.5, 1, -1.3, 0.7, 0.8, 0.9]
)
bar = go.Bar(x=[0, 1, 2, 3, 4, 5],
y=[2, 0.5, 0.7, -1.2, 0.3, 0.4]
)
fig = go.Figure(data = [sca,bar])
pyplt(fig)71 pyecharts导入包:import pyecharts
pyecharts.__version__ # '1.7.1'绘制图(自动打开html):bar = (
Bar()
.add_xaxis([0, 1, 2, 3, 4, 5])
.add_yaxis('ybar',[1.5, 1, -1.3, 0.7, 0.8, 0.9])
)
line = (Line()
.add_xaxis([0, 1, 2, 3, 4, 5])
.add_yaxis('yline',[2, 0.5, 0.7, -1.2, 0.3, 0.4])
)
bar.overlap(line)
bar.render_notebook()大家在复现代码时,需要注意API与包的版本紧密相关,与上面版本不同的包其内的API可能与以上写法有略有差异,大家根据情况自行调整即可。matplotlib 绘制三维 3D 图形的方法,主要锁定在绘制 3D 曲面图和等高线图。72 理解 meshgrid要想掌握 3D 曲面图,需要首先理解 meshgrid 函数。导入包:import numpy as np
import matplotlib.pyplot as plt创建一维数组 xnx, ny = (5, 3)
x = np.linspace(0, 1, nx)
x
# 结果
# array([0.
, 0.25, 0.5 , 0.75, 1.
])创建一维数组 yy = np.linspace(0, 1, ny)
y
# 结果
# array([0. , 0.5, 1. ])使用 meshgrid 生成网格点:xv, yv = np.meshgrid(x, y)
xvxv 结果:array([[0.
, 0.25, 0.5 , 0.75, 1.
],
[0.
, 0.25, 0.5 , 0.75, 1.
],
[0.
, 0.25, 0.5 , 0.75, 1.
]])yv 结果:array([[0. , 0. , 0. , 0. , 0. ],
[0.5, 0.5, 0.5, 0.5, 0.5],
[1. , 1. , 1. , 1. , 1. ]])绘制网格点:plt.scatter(xv.flatten(),yv.flatten(),c='red')
plt.xticks(ticks=x)
plt.yticks(ticks=y)以上就是 meshgrid 功能:创建网格点,它是绘制 3D 曲面图的必用方法之一。73 绘制曲面图导入 3D 绘图模块:from mpl_toolkits.mplot3d import Axes3D生成X,Y,Z# X, Y
x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x, y)
# x-y 平面的网格
R = np.sqrt(X ** 2 + Y ** 2)
# Z
Z = np.sin(R)绘制 3D 曲面图:fig = plt.figure()
ax = Axes3D(fig)
plt.xticks(ticks=np.arange(-5,6))
plt.yticks(ticks=np.arange(-5,6))
ax.plot_surface(X, Y, Z, cmap=plt.get_cmap('rainbow'))
plt.show()74 等高线图以上 3D 曲面图的在 xy平面、 xz平面、yz平面投影,即是等高线图。xy 平面投影得到的等高线图:fig = plt.figure()
ax = Axes3D(fig)
plt.xticks(ticks=np.arange(-5,6))
plt.yticks(ticks=np.arange(-5,6))
ax.contourf(X, Y, Z, zdir='z', offset=-1, cmap=plt.get_cmap('rainbow'))
plt.show()三、 Python 习惯 26 例75 / 返回浮点数即便两个整数,/ 操作也会返回浮点数In [1]: 8/5
Out[1]: 1.676 // 得到整数部分使用 //快速得到两数相除的整数部分,并且返回整型,此操作符容易忽略,但确实很实用。In [2]: 8//5
Out[2]: 1
In [3]: a = 8//5
In [4]: type(a)
Out[4]: int77 % 得到余数%得到两数相除的余数:In [6]: 8%5
Out[6]: 378 ** 计算乘方** 计算几次方In [7]: 2**3
Out[7]: 879 交互模式下的_在交互模式下,上一次打印出来的表达式被赋值给变量 _In [8]: 2*3.02+1
Out[8]: 7.04
In [9]: 1+_
Out[9]: 8.0480 单引号和双引号微妙不同使用单引号和双引号的微妙不同使用一对双引号时,打印下面串无需转义字符:In [10]: print("That isn't a horse")
That isn't a horse使用单引号时,需要添加转义字符 \:In [11]: print('That isn\'t a horse')
That isn't a horse81 跨行连续输入符串字面值可以跨行连续输入;一种方式是用一对三重引号:""" 或 '''In [12]: print("""You're just pounding two
...: coconut halves together.""")
You're just pounding two
coconut halves together.82 数字和字符串In [13]: 3*'Py'
Out[13]: 'PyPyPy'83 连接字面值堆积起来就行,什么都不用写:In [14]: 'Py''thon'
Out[14]: 'Python'84 for 和 else一般语言 else 只能和 if 搭,Python 中却支持 for 和 else, try 和 else.for 和 else 搭后,遍历结束便会执行 elseIn [29]: for i in range(3):
...:
for j in range(i):
...:
print(j)
...:
else:
...:
print('第%d轮遍历结束\n'%(i+1,))
...:
第1轮遍历结束
0
第2轮遍历结束
0
1
第3轮遍历结束85. if not x直接使用 x 和 not x 判断 x 是否为 None 或空x = [1,3,5]
if x:
print('x is not empty ')
if not x:
print('x is empty')下面写法不够 Pythonerif x and len(x) > 0:
print('x is not empty ')
if x is None or len(x) == 0:
print('x is empty')86. enumerate 枚举直接使用 enumerate 枚举容器,第二个参数表示索引的起始值x = [1, 3, 5]
for i, e in enumerate(x, 10): # 枚举
print(i, e)下面写法不够 Pythoner:i = 0
while i < len(x):
print(i+10, x[i])
i+=187. in判断字符串是否包含某个子串,使用in明显更加可读:x = 'zen_of_python'
if 'zen' in x:
print('zen is in')find 返回值 要与 -1 判断,不太符合习惯:if x.find('zen') != -1:
print('zen is in')88 zip 打包使用 zip 打包后结合 for 使用输出一对,更加符合习惯:keys = ['a', 'b', 'c']
values = [1, 3, 5]
for k, v in zip(keys, values):
print(k, v)下面不符合 Python 习惯:d = {}
i = 0
for k in keys:
print(k, values[i])
i += 189 一对 '''打印被分为多行的字符串,使用一对 ''' 更加符合 Python 习惯:print('''"Oh no!" He exclaimed.
"It's the blemange!"''')下面写法就太不 Python 风格:print('"Oh no!" He exclaimed.\n' +
'It\'s the blemange!"')90 交换元素直接解包赋值,更加符合 Python 风格:a, b = 1, 3
a, b = b, a
# 交换a,b不要再用临时变量 tmp ,这不符合 Python 习惯:tmp = a
a = b
b = tmp91 join 串联串联字符串,更习惯使用 join:chars = ['P', 'y', 't', 'h', 'o', 'n']
name = ''.join(chars)
print(name)下面不符合 Python 习惯:name = ''
for c in chars:
name += c
print(name)92 列表生成式列表生成式构建高效,符合 Python 习惯:data = [1, 2, 3, 5, 8]
result = [i * 2 for i in data if i & 1] # 奇数则乘以2
print(result) # [2, 6, 10]下面写法不够 Pythoner:results = []
for e in data:
if e & 1:
results.append(e*2)
print(results)93 字典生成式除了列表生成式,还有字典生成式:keys = ['a', 'b', 'c']
values = [1, 3, 5]
d = {k: v for k, v in zip(keys, values)}
print(d)下面写法不太 Pythoner:d = {}
for k, v in zip(keys, values):
d[k] = v
print(d)94 __name__ == '__main__'有啥用曾几何时,看这别人代码这么写,我们也就跟着这么用吧,其实还没有完全弄清楚这行到底干啥。def mymain():
print('Doing something in module', __name__)
if __name__ == '__main__':
print('Executed from command line')
mymain()加入上面脚本命名为 MyModule,不管在 vscode 还是 pycharm 直接启动,则直接打印出:Executed from command line
Doing something in module __main__这并不奇怪,和我们预想一样,因为有无这句 __main__ ,都会打印出这些。但是当我们 import MyModule 时,如果没有这句,直接就打印出:In [2]: import MyModule
Executed from command line
Doing something in module MyModule只是导入就直接执行 mymain 函数,这不符合我们预期。如果有主句,导入后符合预期:In [6]: import MyModule
In [7]: MyModule.mymain()
Doing something in module MyModule95 字典默认值In[1]: d = {'a': 1, 'b': 3}
In[2]: d.get('b', [])
# 存在键 'b'
Out[2]: 3
In[3]: d.get('c', [])
# 不存在键 'c',返回[]
Out[3]: []96 lambda 函数lambda 函数使用方便,主要由入参和返回值组成,被广泛使用在 max, map, reduce, filter 等函数的 key 参数中。如下,求 x 中绝对值最大的元素,key 函数确定abs(x)作为比较大小的方法:x = [1, 3, -5]
y = max(x, key=lambda x: abs(x))
print(y) # -5 97 max求 x 中绝对值最大的元素,key 函数确定abs(x)作为比较大小的方法:x = [1, 3, -5]
y = max(x, key=lambda x: abs(x))
print(y) # -5 98 mapmap 函数映射 fun 到容器中每个元素,并返回迭代器 xx = map(str, [1, 3, 5])
for e in x:
print(e, type(e))下面写法不够 Pythonerfor e in [1, 3, 5]:
print(e, str(e)) # '1','3','5'99 reducereduce 是在 functools 中,第一个参数是函数,其必须含有 2 个参数,最后归约为一个标量。from functools import reduce
x = [1, 3, 5]
y = reduce(lambda p1, p2: p1*p2, x)
print(y) # 15下面写法不够 Pythoner:y = 1
for e in x:
y *= e
print(y)100 filter使用 filter 找到满足 key 函数指定条件的元素,并返回迭代器如下,使用 filter 找到所有奇数:x = [1, 2, 3, 5]
odd = filter(lambda e: e % 2, x)
for e in odd:
# 找到奇数
print(e)还有另外一种方法,使用列表生成式,直接得到一个odd 容器,odd = [e for e in x if e % 2]
print(odd) # [1,3,5]下面写法最不符合 Python 习惯:odd = []
for e in x:
if e % 2:
odd.append(e)
print(odd)
# [1,3,5]

我要回帖

更多关于 苹果手机的10次方怎么打 的文章

 

随机推荐