Python 学习笔记一


1、

'/' performs float division and '//' performs integer division

<span style="color:#39424e;">>>> </span><span style="color:#ff0000;">from __future__ import division</span><span style="color:#39424e;">
>>> print 4/3
1.3333333333333333 
>>> print 4//3
1</span>

2、

One of the built-in functions of Python is divmod, which takes two arguments  a  and  b  and returns a tuple containing the quotient of  a/b  ( a//b ) and remainder  a .

Here  a/b  can be compared with integer division  a//b .

>>> print divmod(177,10)
(17, 7)

Here 177//10 => 17 and 177%10 => 7

3、

We have only heard of the powers of Python, so far; now we will witness them :)

Power or exponent in Python can be calculated using the built-in power function. Which can be called as for  ab

>>> pow(a,b) 

or

>>> a**b

It's also possible to calculate  abmodm .

>>> pow(a,b,m)  

This is very helpful in computations where you have to print result % mod.

Note that here  a  and  b  can be floats and even negatives; but if a third argument is present,  cannot be negative.

Note Python has a module math, which has its own pow() but it takes two arguments and returns a float. Frankly speaking, we will never use math.pow()



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值