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的更多相关文章

  1. Dive in python Chapter3 实例

    def buildConnectionString(params): """Build a connection string from a dictionary Ret ...

  2. 【Python编程:从入门到实践】chapter3 列表简介

    chapter3 列表简介3.1 列表是什么 列表是一系列按特定顺序排列的元素组成. bicycle = ['trek','cannondale'] print bicycle 3.1.1 访问列表元 ...

  3. Head First Python 学习笔记-Chapter3:文件读取和异常处理

    第三章中主要介绍了简单的文件读取和简单的异常处理操作. 首先建立文件文件夹:HeadFirstPython\chapter3,在Head First Pythong官方站点下载须要使用的文件:sket ...

  4. python自然语言处理——学习笔记:Chapter3纠错

    2017-12-06更新:很多代码执行结果与书中不一致,是因为python的版本不一致.如果发现有问题,可以参考英文版: http://www.nltk.org/book/ 第三章,P87有一段处理h ...

  5. Python Algorithms – chapter3 计数初步

    一些基本递归式的解决方案及其应用实例 主定理的三种情况 排序算法之侏儒排序法 def gnomesort(seq): i = 0 while i < len(seq): if i == 0 or ...

  6. 数据结构:链表(python版)续:带有尾节点引用的单链表

    #!/usr/bin/env python # -*- coding:utf-8 -*- from chapter3.single_linked_list import LNode,LinkedLis ...

  7. 笔记之Python网络数据采集

    笔记之Python网络数据采集 非原创即采集 一念清净, 烈焰成池, 一念觉醒, 方登彼岸 网络数据采集, 无非就是写一个自动化程序向网络服务器请求数据, 再对数据进行解析, 提取需要的信息 通常, ...

  8. 《Python核心编程》 第三章 Python基础 - 练习

    创建文件: # -*- coding: gbk -*- #! /auto/ERP/python_core/chapter ''' Created on 2014年5月21日 @author: user ...

  9. Python学习_从文件读取数据和保存数据

    运用Python中的内置函数open()与文件进行交互 在HeadFirstPython网站中下载所有文件,解压后以chapter 3中的“sketch.txt”为例: 新建IDLE会话,首先导入os ...

随机推荐

  1. 【Head First Servlets and JSP】笔记13:session & cookie

    session的接口 杀死会话 cookie的性质 cookie的接口 再总结——cookie.session.JSESSIONID的前世今生 简单的定制cookie示例 1.session的接口,配 ...

  2. 函数进阶之结合tornado

    一.本篇博文内容 .协程函数 .面向过程编程 .递归和二分法 二.协程函数 协程函数:就是使用了yield表达式形式的生成器 首先函数的传参有几种? 三种: 1.实参形参传参 2.闭包的形式传参 3. ...

  3. mini2440移植uboot 2014.04(六)

    上一篇博文:<mini2440移植uboot 2014.04(五)> 代码已经上传到github上:https://github.com/qiaoyuguo/u-boot-2014.04- ...

  4. 大话设计模式之PHP篇 - 适配器模式

    定义将一个类的接口转换成客户希望的另外一个接口,使用原本不兼容的而不能在一起工作的那些类可以在一起工作. 角色Target适配目标,该角色定义把其他类转换为何种接口,也就是我们的期望接口.Adapte ...

  5. 关于form表单中button按钮自动提交问题

    坑:点击确认按钮,form表单提交2次,发送后台2次请求 //错误代码: <Button id="btnSubmit" name="btnSubmit" ...

  6. Yii和ThinkPHP对比杂谈

    关于ThinkPHP(以下简称TP)和Yii Framework(以下简称Yii)的背景.作者和速度方面就不涉及了.因为速度是一个很复杂的问题,牵扯的因素很多.我不得不承认ThinkPHP是 一个是国 ...

  7. No input clusters found in output/ZS_TEST_OUTPUT3404268420/clusters-0/part-randomSeed. Check your -c argument.

    错误原因可能为: -i 后面参数路径对应的目录或文件中的数据为空,即输入集为空,所以找不到cluster

  8. 图片的另一种展现—将后台图片编码直接展现为图片

    1.应用场景            开发过程中,遇到这样的需求:需要将服务器上的图片展现在页面上,但是图片所在服务器不是对外的,图片所在服务器与应用服务器也不在同一台机器上,这时候就需要在开发中先将图 ...

  9. R语言笔记005——计算描述性统计量

    数据的分布特征: 分布的集中趋势,反应各数据向其中心值靠拢或聚集的程度(平均数,中位数,四分位数,众数) 分布的离散程度,反应各数据远离其中心值的趋势(极差,四分位差,方差,标准差,离散系数) 分布的 ...

  10. js建造者(生成器)模式

    建造者模式将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 在软件系统中,有时需要创建一个复杂对象,并且这个复杂对象由其各部分子对象通过一定的步骤组合而成. 建造者模式类图: ...