think python chapter3
3.1 built-in function
type(42)=> <class 'int'>
int('32')=>32
int(3.9) => 3
int(-2.3)=>-2
float(32)=> 32.0
float('3.14159')=>3.14159
str(32) => '32'
str(3.14159)=>'3.14159'
3.2 define a function
Defining a function creates a function object, which has type function.
you have to create a function before you can run it. In other words, the function definition has to run before the function gets called.
The rules for function names are the same as for variable names: letters, numbers and underscore are legal, but the first character can’t be a number.
Single quotes and double quotes do the same thing; most people use single quotes except in cases like this where a single quote (which is also an apostrophe) appears in the string.
Function definitions get executed just like other statements, but the effect is to create function objects. The statements inside the function do not run until the function is called, and the function definition generates no output.
3.3 flow of execution
Execution always begins at the first statement of the program. Statements are run one at a time, in order from top to bottom.
Function definitions do not alter the flow of execution of the program, but remember that statements inside the function don’t run until the function is called.
A function call is like a detour in the flow of execution. Instead of going to the next state- ment, the flow jumps to the body of the function, runs the statements there, and then comes back to pick up where it left off.
3.8 Variables and parameters are local
When you create a variable inside a function, it is local, which means that it only exists inside the function.
think python chapter3的更多相关文章
- Dive in python Chapter3 实例
def buildConnectionString(params): """Build a connection string from a dictionary Ret ...
- 【Python编程:从入门到实践】chapter3 列表简介
chapter3 列表简介3.1 列表是什么 列表是一系列按特定顺序排列的元素组成. bicycle = ['trek','cannondale'] print bicycle 3.1.1 访问列表元 ...
- Head First Python 学习笔记-Chapter3:文件读取和异常处理
第三章中主要介绍了简单的文件读取和简单的异常处理操作. 首先建立文件文件夹:HeadFirstPython\chapter3,在Head First Pythong官方站点下载须要使用的文件:sket ...
- python自然语言处理——学习笔记:Chapter3纠错
2017-12-06更新:很多代码执行结果与书中不一致,是因为python的版本不一致.如果发现有问题,可以参考英文版: http://www.nltk.org/book/ 第三章,P87有一段处理h ...
- Python Algorithms – chapter3 计数初步
一些基本递归式的解决方案及其应用实例 主定理的三种情况 排序算法之侏儒排序法 def gnomesort(seq): i = 0 while i < len(seq): if i == 0 or ...
- 数据结构:链表(python版)续:带有尾节点引用的单链表
#!/usr/bin/env python # -*- coding:utf-8 -*- from chapter3.single_linked_list import LNode,LinkedLis ...
- 笔记之Python网络数据采集
笔记之Python网络数据采集 非原创即采集 一念清净, 烈焰成池, 一念觉醒, 方登彼岸 网络数据采集, 无非就是写一个自动化程序向网络服务器请求数据, 再对数据进行解析, 提取需要的信息 通常, ...
- 《Python核心编程》 第三章 Python基础 - 练习
创建文件: # -*- coding: gbk -*- #! /auto/ERP/python_core/chapter ''' Created on 2014年5月21日 @author: user ...
- Python学习_从文件读取数据和保存数据
运用Python中的内置函数open()与文件进行交互 在HeadFirstPython网站中下载所有文件,解压后以chapter 3中的“sketch.txt”为例: 新建IDLE会话,首先导入os ...
随机推荐
- 什么是make config,make menuconfig,make oldconfig,make xconfig,make defconfig,make gconfig?【转】
本文转载自;https://blog.csdn.net/baweiyaoji/article/details/52876701 在进行内核配置,或者是对一些软件的配置和编译中,常常会遇到: make ...
- URL重写技术总结
URL重写技术总结 概要:什么是url重写? URL 重写是截取传入 Web 请求并自动将请求重定向到其他 URL 的过程.比如浏览器发来请求 hostname/101.html ,服务器自动将这个请 ...
- html里id和name的异同
id与name的作用,作为标签的标识符,基本上是一样的. name是老方法,id是在name基础上发明的,比name“现代化”一点,用的范围广一点 <...>中的name原来(刚发明时)就 ...
- mssql 函数STUFF 的用法
DECLARE @limitDay INT;SET @limitDay = 92;IF DATEDIFF(DAY, '2017-12-13 00:00:00', '2017-12-13 18:00:0 ...
- 0.00-050613_boot.s
! boot.s ! ! It then loads the system at 0x10000, using BIOS interrupts. Thereafter ! it disables al ...
- JDBC方式操作数据库
1.读取配置文件,我将配置信息写入配置文件(.properties)中,方便后期数据库变更后或者其他项目使用,扩展性好些,尽量避免硬编码. driver=oracle.jdbc.driver.Orac ...
- Linux下Apache的安装与配置
本文安装的httpd版本为httpd 2.4.4安装之前确保 Development Libraries与Development tools安装上.安装方法参考:http://www.linuxidc ...
- UGUI加载图片优化方法之一:打包成图集
打包后的: 直接改变sprite中的packing tag,相同的packing tag就是同一张图集中的.改完运行会自动帮你打包
- web 程序中的编码
比如字符串 <script type="text/javascript">alert('跨站攻击鸟')</script> 1.html encode ...
- js执行环境、作用域
js执行环境.作用域 执行环境:是javascript中的一个重要的概念,<javascript高级程序设计第三版>的定义是:执行环境定义了变量或函数有权访问的其他数据,决定了他们各自的行 ...