首页 > 代码库 > <Python> Random Tricks
<Python> Random Tricks
1. with-as (context-manager)
with function() as instance:
#do something
Codes above do the following:
Let instance = function(), where function returns an instantiation of some object, and this object has defined method __enter__() and __exit__().
In addition, before do something, execute __enter__(),
and after do something, execute __exit__() which are defined in the class of instance.
For detail, see http://blog.csdn.net/suwei19870312/article/details/23258495
2. basic data type manipulation
example:
[1] + [2] -> [1, 2]
[1] * 3 = [1, 1, 1] (or written as [1 for _ in range(3)])
#to be supplemented
<Python> Random Tricks
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。