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 ...
随机推荐
- java利用反射将pojo转为json对象
最近做以太坊钱包项目需要与前台进行json交互,写一个工具类,经普通javaBean转为json对象 package util; import java.lang.reflect.Field; imp ...
- Hearbeat 介绍
Hearbeat 介绍 Linux-HA的全称是High-Availability Linux,它是一个开源项目,这个开源项目的目标是:通过社区开发者的共同努力,提供一个增强linux可靠性(reli ...
- CSS3 3D旋转按钮对话框
在线演示 本地下载
- gem Errno::ECONNRESET: Connection reset by peer - SSL_connect
问题描述 在使用gem安装软件包时,会时常遇到下面的问题: ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) Errno: ...
- 20145240《Java程序设计》第二周学习总结
20145240 <Java程序设计>第二周学习总结 教材学习内容总结 本周主要学习了第三章的内容,讲的是Java的一些基础语法,包括两大系统类型.变量.运算符的基本使用.类型转换及几个基 ...
- Adroid真机调试
几次想学Android,都因为启动模拟器调试时太慢而放弃. 今天终于搞通了真机调试,记录一下: 1)USB线把手机和电脑连接. 2)Adroid手机启用USB调试. 3)命令行运行 adb devic ...
- poj 3468 线段树模板题
#include<iostream> #include<algorithm> #include<stdio.h> using namespace std; #def ...
- cuffdiff problem--Performed 0 isoform-level transcription difference tests
如何解决cuffdiff运行结果中表达量为0的情况? cuffdiff -o cdiffout -b ref.fasta -u -p 15 --library-type fr-firststrand ...
- springboot+mybatis+springSecurity+thymeleaf
配置步骤: .pom <dependencies> <dependency> <groupId>org.springframework.security</g ...
- linux基础(6)-shell编程
shell脚本 shell脚本程序:以文件形式存放批量的linux命令集合,该文件能够被shell释放执行.通常由一段linux命令.shell命令.控制语句以及注释语句构成. shell脚本特点: ...