Python学习异常检测
2017-08-21 18:05
211 查看
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 21 14:11:22 2017
@author: cq
"""
#python处理异常
try :
2/0
except Exception,e: #其中e为实例,即错误的实况
print(e)
try:
a = 1/0
except Exception,e:
print e
finally:
print 'hehehe'
try:
a = 1/2
except Exception,e:
print e
else:
print 'success'
try:
1/0
except IndexError:
print 'qqq'
except ZeroDivisionError:
print 'eeee'
finally:
print('you will die')
#学习生成器
def fib(max):
a,b=1,1
while a<max:
yield a #generators return an iterator that returns a stream of values
a,b=b,a+b
for n in fib(15):
print(n)
#学习私有属性,私有属性在外界是访问不了的
class Person:
def __init__(self):
self.__name='haha'#私有属性
self.age=22
def __get_name(self):#私有方法
return self.__name
def get_age(self):
return self.age
person=Person()
print(person.get_age())
print(person.__get_name())
#学习time
import time
time.time()
time.localtime(time.time())
time.strftime('%Y-%m-%d',time.localtime(time.time()))
time.localtime(time.time())[:3]
"""
Created on Mon Aug 21 14:11:22 2017
@author: cq
"""
#python处理异常
try :
2/0
except Exception,e: #其中e为实例,即错误的实况
print(e)
try:
a = 1/0
except Exception,e:
print e
finally:
print 'hehehe'
try:
a = 1/2
except Exception,e:
print e
else:
print 'success'
try:
1/0
except IndexError:
print 'qqq'
except ZeroDivisionError:
print 'eeee'
finally:
print('you will die')
#学习生成器
def fib(max):
a,b=1,1
while a<max:
yield a #generators return an iterator that returns a stream of values
a,b=b,a+b
for n in fib(15):
print(n)
#学习私有属性,私有属性在外界是访问不了的
class Person:
def __init__(self):
self.__name='haha'#私有属性
self.age=22
def __get_name(self):#私有方法
return self.__name
def get_age(self):
return self.age
person=Person()
print(person.get_age())
print(person.__get_name())
#学习time
import time
time.time()
time.localtime(time.time())
time.strftime('%Y-%m-%d',time.localtime(time.time()))
time.localtime(time.time())[:3]
相关文章推荐
- python 机器学习实战:信用卡欺诈异常值检测
- python学习二(文件与异常)
- python 异常学习1
- Python3 学习第三弹:异常情况如何处理?
- [Python]OpenCV学习总结及文字检测
- Python菜鸟学习手册11----异常处理
- python学习笔记——异常
- Python学习笔记(4)--异常处理
- Python学习笔记012_网络_异常
- [IT学习]Python如何处理异常特殊字符
- Python基础教程 第8章: 异常 学习笔记
- Python学习:使用boost c++嵌入python,获取异常信息输出到字符串
- python学习笔记——8_异常
- 【Scikit-Learn 中文文档】二十五:新异类和异常值检测 - 无监督学习 - 用户指南 | ApacheCN
- 【Scikit-Learn 中文文档】新异类和异常值检测 - 无监督学习 - 用户指南 | ApacheCN
- Python学习笔记006_异常_else_with
- python学习—Day18—异常
- 学习python时常出现的异常
- python异常值检测与相关系数
- python学习-异常