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. html5-entities.js消失问题

    今天用nuxt做项目时,启动npm run dev,项目正常启动, 可过一会儿再试图启动时却报错: * ./libhtml5-entities.js in ./~/html-entities/inde ...

  2. php的正则表达式

    这篇文章介绍的内容是关于php的正则表达式 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下. 正则表达式是一种描述字符串结果的语法规则,是一个特定的格式化模式,可以匹配.替换.截取匹配 ...

  3. XXL-Job高可用集群搭建

    如果XXL-Job admin挂掉就完蛋了,所有任务无法执行 调度中心:管理任务的触发 调度中心如何实现集群? XXL-Job如何实现集群? 底层已经实现好了!文档里面有的 如果想实现Job集群:   ...

  4. 最长k可重区间集

      P3358 最长k可重区间集问题 P3357 最长k可重线段集问题 P3356 火星探险问题 P4012 深海机器人问题 P3355 骑士共存问题 P2754 [CTSC1999]家园 题目描述 ...

  5. navigationBar

    1.navigationBar导航条可以看做是self.navigationController导航控制器的一个属性. 通过self.navigationController.navigationBa ...

  6. js中介者模式

    中介者模式(Mediator),用一个中介者对象来封装一系列对象交互.中介者使各对象不需要显示地相互引用,从而使其松散,而且可以独立地改变它们之间的交互. 从生活中例子自然知道,中介者模式设计两个具体 ...

  7. 《Advanced Bash-scripting Guide》学习(四):一个显示时间日期登录用户的脚本

    本文所选的例子来自于<Advanced Bash-scripting Gudie>一书,译者杨春敏 黄毅 编写一个脚本,显示时间和日期,列出所有的登录用户,显示系统的更新时间.然后这个脚本 ...

  8. python中的excel操作

    一. Excel在python中的应用 存测试数据 有的时候大批量的数据,我们需要存到数据库中,在测试的时候才能用到.测试的时候就从数据库中读取出来.这点是非常重要的! 存测试结果 二. Excel中 ...

  9. zoj 1375 贪心

    https://vjudge.net/problem/ZOJ-1375 In modern day magic shows, passing through walls is very popular ...

  10. windows7安装PyQt5(通过pip install 安装)

    开始接触PyQt5 ,总结了一下安装的方法 默认各位已经安装好了Python环境 首先,确定一下之前没有安装过pyqt5,如果安装了,可以先卸载,避免出现意外, 之前装了几次没成功就是这种情况,卸载命 ...