[docs] Function Int()

bob gailer bgailer at gmail.com
Tue Jun 4 15:15:39 CEST 2013


On 2/26/2013 9:41 AM, Colin Morley wrote:
> Hi
I just found your post - and see no reply, so I will reply.
>
>
> I'm not a Python expert -- barely a novice, but the entry for the 
> function INT() on both 2.7 and 3.3 versions is headed
>
> INT(x=0)...
actually it is int(x=0). Python is case sensitive!
>
>
> Which does not seem to make much sense to me -- shouldn't it be INT(x)?
>
> (X=0) is true or false (1 or 0)  depending on the value of x.
actually comparison uses ==. x==0 would yiels True or False. Note again 
case is important.
>
>
> Apologies if this is nonsense
Just not clearly understanding.

When you define a function you can make a parameter optional by the 
syntax parameter = default value.

int(x=0) thus is shorthand for saying "if you don't provide a value for 
x it will be assigned the value 0.

You could have discovered this by reading the docs. "Convert a number or 
string x to an integer, or return 0 if no arguments are given."


-- 
Bob Gailer
919-636-4239
Chapel Hill NC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20130604/9237a084/attachment.html>


More information about the docs mailing list