随笔分类 -  Python

摘要:# Python's list comprehensions are awesome. vals = [expression for value in collection if condition] # This is equivalent to: vals = [] for value in collection: if condition:... 阅读全文
posted @ 2017-11-09 19:04 Zhentiw 阅读(176) 评论(0) 推荐(0) 编辑
摘要:def myfunc(x, y, z): print(x, y, z) tuple_vec = (1, 0, 1) dict_vec = {'x': 1, 'y': 0, 'z': 1} >>> myfunc(*tuple_vec) 1, 0, 1 >>> myfunc(**dict_vec) 1, 0, 1 阅读全文
posted @ 2017-10-12 18:20 Zhentiw 阅读(250) 评论(0) 推荐(0) 编辑
摘要:# Why Python is Great: Namedtuples # Using namedtuple is way shorter than # defining a class manually: >>> from collections import namedtuple >>> Car = namedtup1e('Car', 'color mileage') # Our new "... 阅读全文
posted @ 2017-10-03 20:59 Zhentiw 阅读(235) 评论(0) 推荐(0) 编辑
摘要:# The get() method on dicts # and its "default" argument name_for_userid = { 382: "Alice", 590: "Bob", 951: "Dilbert", } def greeting(userid): return "Hi %s!" % name_for_userid.get(... 阅读全文
posted @ 2017-10-01 18:30 Zhentiw 阅读(178) 评论(0) 推荐(0) 编辑
摘要:x, y, z = 0, 1, 0 if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') # These only test for truthiness: if x or y or z: print('passed') if any((x, y, z))... 阅读全文
posted @ 2017-09-27 20:00 Zhentiw 阅读(188) 评论(0) 推荐(0) 编辑
摘要:In JS, we have object spread opreator: In python we can do: 阅读全文
posted @ 2017-09-26 16:25 Zhentiw 阅读(205) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示