[N00B]什么是%? [英] [N00B] What's %?

查看:97
本文介绍了[N00B]什么是%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!它已经有一个星期的时间学习python了!

我已经阅读了''绝对优势的python编程''

我不明白%喜欢......


107%4 = 3

7%3 = 1


我是与师混淆:/

请帮帮我...


thx 4阅读。

解决方案

2005-02-10,administrata< ad ********** @ hotmail.com>写道:

我不理解%... ...

107%4 = 3
7%3 = 1




它是模数运算符。它返回整数

除法的余数。正如我们以前在二年级时说的那样:


4进入107 26次,剩下3次。


3进入4次2次剩下1个。


-

格兰特爱德华兹格兰特哇!如果我拉这个SWITCH

我会是RITA HAYWORTH !!或者

visi.com一位SCIENTOLOGIST!


administrata on 2005-02-10 09:38:41 -0800:
< blockquote class =post_quotes>嗨!它已经花了大约一个星期的时间学习python!
我已经读过''python编程的绝对乞讨者''
我不明白%喜欢......

107%4 = 3
7%3 = 1

我对分歧很困惑:/




这不是分裂;除法运算符是''/''。这是mod

函数,它返回余数 - 例如,7除以3是

2余数1,所以7%3返回1.


-----开始PGP SIGNATURE -----

版本:GnuPG v1.2.6(NetBSD)


iD8DBQFCC54sAud / 2YgchcQRAo0GAJ0al6lQYfEie1YL1Ul9P9tACYuZwACggtGf

bnBmlm25CgcfT0jgsb5C4As =

= ktys

----- END PGP SIGNATURE -----


administrataéécrit:

嗨!它已经花了大约一个星期的时间学习python!
我已经读过''python编程的绝对乞讨者''
我不明白%喜欢......

107%4 = 3
7%3 = 1


它是模数运算符(如果你不记得,模数是

剩余的整数除法,即5%2 = 1)


最常用的一个用于测试数字是奇数还是偶数:


any_even_number%2 == 0

any_odd_number%2 == 1

注意%运算符也用于字符串格式化,即:

"%d modulo%d =%d" %(5,2,1)

=> 5模2 = 1

请帮帮我......



HTH

布鲁诺


Hi! it''s been about a week learning python!
I''ve read ''python programming for the absolute begginer''
I don''t understand about % like...

107 % 4 = 3
7 % 3 = 1

I''m confused with division :/
Please help me...

thx 4 reading.

解决方案

On 2005-02-10, administrata <ad**********@hotmail.com> wrote:

I don''t understand about % like...

107 % 4 = 3
7 % 3 = 1



It''s the modulus operator. It returns the remainder of integer
division. As we used to say in second grade:

4 goes into 107 26 times with 3 left over.

3 goes into 4 2 times with 1 left over.

--
Grant Edwards grante Yow! If I pull this SWITCH
at I''ll be RITA HAYWORTH!! Or
visi.com a SCIENTOLOGIST!


administrata on 2005-02-10 09:38:41 -0800:

Hi! it''s been about a week learning python!
I''ve read ''python programming for the absolute begginer''
I don''t understand about % like...

107 % 4 = 3
7 % 3 = 1

I''m confused with division :/



It''s not division; the division operator is ''/''. It''s the mod
function, which returns the remainder - for example, 7 divided by 3 is
2 remainder 1, so 7 % 3 returns 1.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iD8DBQFCC54sAud/2YgchcQRAo0GAJ0al6lQYfEie1YL1Ul9P9tACYuZwACggtGf
bnBmlm25CgcfT0jgsb5C4As=
=ktys
-----END PGP SIGNATURE-----


administrata a écrit :

Hi! it''s been about a week learning python!
I''ve read ''python programming for the absolute begginer''
I don''t understand about % like...

107 % 4 = 3
7 % 3 = 1
it''s the modulo operator (if you don''t remember, the modulo is the
remaining of the integer division, ie 5 % 2 = 1)

One of the most commun use is to test wether a number is odd or even:

any_even_number % 2 == 0
any_odd_number % 2 == 1
Note that the % operator is also used for string formating, ie:
"%d modulo %d = %d" % (5, 2, 1)
=> "5 modulo 2 = 1"
Please help me...


HTH
Bruno


这篇关于[N00B]什么是%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆