
python
银灯玉箫
这个作者很懒,什么都没留下…
展开
-
Anaconda 常用命令
conda -Vconda infoconda list --revisionsconda install geopandasconda uninstall protobufconda config --show default_channelsconda config --show channelsconda config --set channel_priority flexibleconda config --set report_errors falseconda .原创 2021-05-28 16:21:14 · 230 阅读 · 0 评论 -
python中defaultdict用法详解
python中defaultdict用法详解认识defaultdict:当我使用普通的字典时,用法一般是dict={},添加元素的只需要dict[element] =value即,调用的时候也是如此,dict[element] = xxx,但前提是element字典里,如果不在字典里就会报错,如:1.png这时defaultdict就能排上用场了,defaultdict的作用是在于,当字典...转载 2019-11-19 15:29:59 · 941 阅读 · 0 评论 -
python字符串判断相等总结
判断字符串相等使用==,不使用is和cmp()函数cmp() 函数则是相当于 <,==,> 但是在 Python3 中,cmp() 函数被移除了,所以我以后还是避免少用这个函数。#-*-conding:utf-8-*-i='新闻';m=input();if i==m: print('yes');else: print('no'); input(); if se...原创 2019-11-11 11:54:51 · 75200 阅读 · 0 评论 -
Effective Python 读书笔记 Item 17:Be Defensive When Iterating Over Arguments
#!/usr/bin/env python3# Copyright 2014 Brett Slatkin, Pearson Education Inc.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with...原创 2019-11-01 15:41:54 · 156 阅读 · 0 评论 -
Effective Python 读书笔记 Item 16:Consider Generators Instead of Returning Lists
import loggingfrom pprint import pprintfrom sys import stdout as STDOUT# Example 1def index_words(text): result = [] if text: result.append(0) for index, letter in enumerate...原创 2019-10-30 18:01:36 · 153 阅读 · 0 评论 -
Effective Python读书笔记 Item 14: Prefer Exceptions to Returning None
# Example 7def divide(a, b): try: return a / b except ZeroDivisionError as e: raise ValueError('Invalid inputs') from e# Example 8x, y = 5, 2try: result = divide(x, y...原创 2019-10-30 17:57:11 · 148 阅读 · 0 评论 -
Effective Python 读书笔记 Item 13 Take Advantage of Each Block in try/except/else/finally
Use try/except/else/finally when you want to do it all in one compound statement.The try/finally compound statement lets you run cleanup code regardless of whether exceptions were raised in the try...原创 2019-10-30 17:14:45 · 203 阅读 · 0 评论 -
Effective Python 读书笔记Item 10:Prefer enumerate Over range
flavor_list = ['vaneee','cee','ww','we']for i,flavor in enumerate (flavor_list): print('%d: %s' % (i+1, flavor))You can make this even shorter by specifying the number from which enumerate should...原创 2019-10-29 15:16:19 · 143 阅读 · 0 评论 -
Effective Python 读书笔记Item 9: Consider Generator Expressions for Large Comprehensions
No Generatorvalue = [len(x) for x in open('/tmp/my_file.txt')]print(value)Using Generator by () charactersit = (len(x) for x in open('/tmp/my_file.txt'))print(next(it))print(next(it))Generat...原创 2019-10-29 15:12:14 · 174 阅读 · 0 评论 -
Effective Python 读书笔记Item 7:Use List Comprehensions Instead of map and filter
a = [1,2,3,4]even_sqaures = [x**2 for x in a if x%2 ==0 ]原创 2019-10-29 14:56:16 · 151 阅读 · 0 评论 -
Effective Python 读书笔记 ITEM5关于slicing
Item 5 Know How to Slice SequencesThe result of slicing a list is a whole new list. References to the objects from the original list are maintained.Modifying the result of slicing won’t affect the o...原创 2019-10-29 14:47:27 · 161 阅读 · 0 评论