一步一步学python(六) - 抽象

1、string转数字

import  locale

locale . atoi( str )

2、创建函数

函数是可以调用(可能包含参数),执行某种行为并返回一个值

>>>import math

>>>x 1

>>>y  math.sqrt

>>>cllable( x )

false

>>>callable( y )

True

使用def定义一个函数

def hello( name ):

return ' Hello,' + name + '  ! '

这样就定义了一个hello函数

3、记录函数

def square( x )

' calculates the square of the number x .'

return x*x

文档可以按如下方式访问

square._doc_

'calculates the square of the number x.'

内建函数help很有用。在交互式解释器中可以得到函数的信息

help(square)


4、关键字参数和默认值、

5、收集参数

def print ( *param )

参数前的*把将所有的值放在一个元组

6、反转过程

7、作用域

除了全局作用域,每个函数都会创建一个作用域

8、递归

函数调用自身称为递归



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值