![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
Dale1991
这个作者很懒,什么都没留下…
展开
-
2-string_working_with_text
video 格式字符串 字符串中包含引号 message_double="Dale's world" message_slash='dale\'s world' message_single='"dale"' #"dale" 字符串切片 print(message_double[0:5原创 2019-02-17 21:03:10 · 153 阅读 · 0 评论 -
Using Try/Except Blocks for Error Handling
文章目录Python 异常处理try and exceptelse and finally引用 Python 异常处理 程序执行中出现的错误提示,对于我们开发人员来说是很方便的,但对于用户来说是不友好的的,因此需要我们定制这些提示信息。 try的工作原理是,当开始一个try语句后,python就在当前程序的上下文中作标记,这样当异常出现时就可以回到这里,try子句先执行,接下来会发生什么依赖于...原创 2019-03-22 17:52:22 · 154 阅读 · 0 评论 -
Generators - How to use them and the benefits you receive
Python Generators are often considered a somewhat advanced topic, but they are actually very easy to understand once you start using them on a regular basis. Actually, after you use generators for so...原创 2019-03-18 14:14:01 · 144 阅读 · 0 评论 -
String Formatting - Advanced Operations for Dicts, Lists, Numbers, and Dates
文章目录String Formating - Dicts, ListString Formating - NumbersString Formating - Dates引用 String Formating - Dicts, List person = {"name":"dale","age":"25"} placeholder 和 format中的参数一一对应。 "my name is {...原创 2019-03-21 10:34:36 · 142 阅读 · 0 评论 -
Sorting Lists, Tuples, and Objects
文章目录对list类型对象排序sortedlist.sort()reverse=True对tuple和dict对象排序参数key=key=abskey= 函数指针、lambda、attrgetter引用 对list类型对象排序 sorted 排序不会改变被排序对象的原始顺序,排序后的对象会以返回值形式输出 li = [9, 4, 5, 6, 2, 1, 3, 7, 8] # sorted :r...原创 2019-03-17 10:54:25 · 194 阅读 · 0 评论 -
Variable Scope - Understanding the LEGB rule and global/nonlocal statements
文章目录LEGB Scopeglobal and localbuild-inEnclosing总结引用 LEGB Scope Local Enclosing Global Build-in 之所以是这样的先后顺序,是因为在调用变量时,python会自动按照这样的顺序去寻找声明(assignment) local: 局部作用域,指的是变量定义在函数范围内 enclosing: global: ...原创 2019-03-20 15:17:56 · 201 阅读 · 0 评论 -
csv.writer写入文件有多余的空行
引用 csv.writer写入文件有多余的空行 with open(‘egg2.csv’, ‘w’, newline=’’) as cf:转载 2019-03-16 10:09:49 · 273 阅读 · 0 评论 -
8-Functon_args_kwargs
文章目录Basic functionargs and kwargs\*args\*\*kwargsargs and kwargs引用 Basic function def hello_func(greeting="none"): return "{} function!".format(greeting) print(hello_func.__str__) <method-wra...原创 2019-03-11 11:24:41 · 249 阅读 · 0 评论 -
Duck Typing and Asking Forgiveness, Not Permission (EAFP)
Pythonic You are following conventions and coding styles of the Python language in order to write clean and readable code Duck Typing 如果一个object叫声向鸭子,走路姿势像鸭子,那么它就是鸭子。 我们不关心操作的实例化对象本身是什么类型(class),...原创 2019-03-19 15:19:29 · 214 阅读 · 0 评论 -
9-Import Modules and Exploring The Standard Library
文章目录导入模块准备步骤导入命令搜索路径默认搜索路径增加搜索路径Python Standard Library引用 导入模块 准备步骤 新建模块:my_module.py 这里定义了一个变量和一个函数,用来在test_module.py中测试调用。print statement是用来检测是否成功导入了模块。 print("this is my module") test = "test ...原创 2019-03-14 22:46:07 · 109 阅读 · 0 评论 -
6-Conditionals_and_Booleans_if_Else_Elif
文章目录if \else\ elif\ statementand\ or\ not\ key-wordsandornot"is" equal "==" ?a和b分别赋值d = cFalse Values:NoneZero of any numeric typeAny empty sequence. For example, '', (), [].Any empty mapping. For exa...原创 2019-03-04 12:06:38 · 187 阅读 · 0 评论 -
5-Dictionaries_working_with_key-value_pairs
文章目录初始化正文index取值get方法updata方法del 函数pop方法key, value, items特殊的一个例子引用 初始化 student = {‘name’: ‘Dale’, “age”: 18, “courses”: [“math”, “science”], 1: “index”} 正文 index取值 print(student[1]) # key值可以是字符串,也可以是...原创 2019-03-04 10:23:20 · 142 阅读 · 0 评论 -
Lambda Expressions & Anonymous Functions
文章目录使用方式没有参数有一个或者多个参数实例排序实例Quadratic functions case总结引用 使用方式 没有参数 a=lambda:&quot;waht is my purpose?&quot; b=a print(id(a)) print(id(b)) # 通过打印ID可知,a和b是指向同一个lambda表达式的(也说明lambda表达式也是临时变量在内存中保存的)。 b() 140291082...原创 2019-03-14 10:10:52 · 185 阅读 · 0 评论 -
7-Loops_Iterations_For_While_Loops
文章目录for loopwhile结束条件infinite loop引用 for loop iteration迭代器依次指代列表中的元素。break statement 会立即结束for循环 nums = [1, 2, 3, 4, 5] for num in nums: if num == 3: print("Found") break prin...原创 2019-03-05 10:29:36 · 174 阅读 · 0 评论 -
mutable_vs_immutable
定义 内容原创 2019-02-28 21:52:58 · 260 阅读 · 0 评论 -
4-lists_tuples_sets
定义变量 courses=[&amp;quot;history&amp;quot;, 'PE', &amp;quot;$&amp;quot;, 'math', 'comsci'] courses_2=['english', 'chinese'] num=[2, 1, 3, 5, 4, 9] slice list print(courses[:2])# 前闭后开 print(courses[-1])# comsci slicing原创 2019-02-28 21:20:05 · 223 阅读 · 0 评论 -
Programming Terms: Closures - How to Use Them and Why They Are Useful
文章目录将函数作为参数传给另一个函数将函数作为返回值返回函数可以嵌套函数可以存储在容器中实现了 _call_ 的类也可以作为函数closures引用 将函数作为参数传给另一个函数 函数接受一个或多个函数作为输入或者函数输出(返回)的值是函数时,我们称这样的函数为高阶函数。 Python内置函数中,典型的高阶函数是 map 函数,map 接受一个函数和一个迭代对象作为参数,调用 map 时,依次迭...原创 2019-03-27 15:05:38 · 134 阅读 · 0 评论