python
EE转CS自学之路
这个作者很懒,什么都没留下…
展开
-
字典中items(),keys(),values()
list中values为数值,keys为前缀,items为整个>>> dict = { 1 : 2, 'a' : 'b', 'hello' : 'world' } >>> dict.values() ['b', 2, 'world'] >>> dict.keys() ['a', 1, 'hello'] >>> dict.items() [('a', 'b'), (1, 2),原创 2017-11-15 15:37:04 · 804 阅读 · 0 评论 -
@property用法
限制参数范围,常规可用:class Student(object): def get_score(self): return self._score def set_score(self, value): if not isinstance(value, int): raise ValueError('score must be原创 2017-11-14 11:28:11 · 138 阅读 · 0 评论 -
面向对象
类(class)和实例(instance)class Student(object)Student为类的名称,object为继承的属性bart = Student()bart指向了student的实例bart.name = 'bill'给实例bart绑定了一个name的属性原创 2017-11-14 11:16:46 · 105 阅读 · 0 评论 -
装饰器
Python的@语法可以把decorator置于函数的定义处先定义一个能打印日志的decoratordef log(func): def wrapper(*args, **kw): print('call %s():' func.__name__) return func(*args,**kw) return wrapper再定义一个函数@logde原创 2017-11-14 10:58:57 · 127 阅读 · 0 评论 -
*args和**kwargs
变量不确定时可用 *args无key值 *args可以容纳多个变量的list:def fun_var_args(farg, *args): print "arg:", farg for value in args: print "another arg:", value fun_var_args(1, "two", 3) # *args可以当作可容纳原创 2017-11-14 10:36:56 · 115 阅读 · 0 评论 -
html结构
每个网页分为两大块和 中标题,段落为,所有链接为 BeautifulSoup中用soup.find_all('a')去找所有选项,再用字典来读取l["href] for l in xxx原创 2018-02-07 15:59:03 · 122 阅读 · 0 评论 -
正则表达式
用re.search() 模块进行匹配 对于寻在潜在的多个文字的可以用r"r[au]n"即可找到“run”和“ran”\d : 任何数字\D : 不是数字\s : 任何 white space, 如 [\t\n\r\f\v]\S : 不是 white space\w : 任何大小写字母, 数字和 “” [a-zA-Z0-9]\W : 不是 \w\b : 空白字符 (只在某个字...原创 2018-02-08 15:41:54 · 106 阅读 · 0 评论 -
python自带数据库sqliter3基本操作
数据库操作读取用read_sql从sqlite数据库中读取数据import sqliter3con = sqlite3.connect('user_information.sqlite')sql = 'select * from user_information LIMIT 3'df = pd.read_sql(sql.con)用index_col参数来规定将哪一列设...原创 2018-07-26 08:28:55 · 3698 阅读 · 1 评论