- 博客(12)
- 收藏
- 关注
原创 进制转换
进制转换十进制-->二进制 倒除法+余数倒序 10/2 5...0 #10(10)--->1010(2) 5/2 2...1 2/2 1...0 1/2 0...1 十进制-->十六进制 40/16 2...8 ...
2018-11-20 09:02:31
161
原创 异常处理
class Test(object):def init(self,switch):self.switch = switchdef calc(self,a,b):try:return print(a/b)except Exception as result:if self.switch:print(“捕获异常成功,结果为:%s”%result)else:print(“抛出异常”)...
2018-11-19 17:05:13
110
原创 模块 包
1.调用模块中的函数from方法from 模块名 import 函数名1,函数名2sleep()from time import * #导入模块下的所有函数sleep(3)import方法import timetime.sleep(3)print(time.localtime())2.as取名①import time as t#模块改名print(t.time()...
2018-11-19 17:05:06
119
转载 raise引出自定义异常
while True: class erro(Exception):#自定义的异常类,是Erro或Exception的子类 def __init__(self,length,at_least): self.length = length self.at_least = at_least def main(): ...
2018-11-08 20:24:39
301
转载 捕获异常
try—except—else—finally出现报错时,except捕获异常,并显示错误原因,如果没有错误,不执行except,而是执行else,finally是无论对错都要执行.加粗样式import timetry: f = open("text1.txt") try: while True: content = f.readlin...
2018-11-08 19:23:42
127
翻译 创建使用类
class Restaurant(): def __init__(self,name,type): self.name = name self.type = type def restaurant_info(self): print("饭店名字为:",self.name) print("餐厅类型是:",self.typ...
2018-11-06 21:35:39
105
原创 子字符串
ming_zi = "芝麻开门.py"if "芝麻" in ming_zi:#"芝麻" 子字符串 print("在")else: print("不在")if "芝麻门" in ming_zi:#不是 print("在")else: print("不在")if "芝麻门" not in mi
2018-11-06 15:32:31
397
原创 输出1--10,舍去4 (pass)
i = 1while i <= 10: if i == 4: pass else: print(i,end=" ") i += 1
2018-11-06 13:18:36
133
原创 time模块和range()函数
ragne(start,end,step)import timedef Time(): sum = 1 for i in range(100,100000,2): sum *= i return sumstart = time.time()xun_huan = Time()print(xun_huan)end = time.time()prin...
2018-11-06 13:11:50
1965
原创 1--100内奇数和,偶数和
i = 1sum1 = 0sum2 = 0while i &lt;= 100: if i % 2 == 0: sum1 += i else: sum2 += i i += 1sum = sum1 + sum2print(sum,sum1,sum2)
2018-11-06 11:37:04
986
原创 求1-2+3-4+5 ... 99的所有数的和
sum = 0i = 1while i &lt;= 99:if i % 2 ==0:sum -= ielse:sum += ii += 1print(sum)
2018-11-06 11:22:06
5881
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人