首页 > 编程语言 > 详细

<Python> Random Tricks

时间:2016-09-01 22:52:04      阅读:275      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/mjust/p/5831554.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!