Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Python beginner

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
cbuffer



Joined: Thu Nov 01, 2007 12:04 am
Posts: 67

PostPosted: Sun May 16, 2010 12:47 am    Post subject: Python beginner Reply with quote

Can someone point me to an explanation of the significance of the L in line 2 please?

>>> pow(2,31)
2147483648L
>>> print pow(2,31)
2147483648

TIA

Ken
Back to top
View user's profile Send private message
graemef



Joined: Wed Apr 07, 2010 9:55 am
Posts: 8

PostPosted: Sun May 16, 2010 3:32 am    Post subject: Reply with quote

The L indicates that the data type is a Long integer. The second version which prints the value converts the numeric to a character string and the data type is not shown.
Back to top
View user's profile Send private message
LeeNukes
LXF regular


Joined: Sun Jun 21, 2009 9:11 pm
Posts: 954
Location: At the bar

PostPosted: Sun May 16, 2010 9:15 am    Post subject: Reply with quote

While on the theme of Python, why are indents such an issue? I used to think they were just to make it easy for people to read, but it stops a program working if they are slightly wrong.
_________________
Join GiffGaff and get 5 free credit
Back to top
View user's profile Send private message
ollie
Moderator


Joined: Mon Jul 25, 2005 12:26 pm
Posts: 2749
Location: Bathurst NSW Australia

PostPosted: Sun May 16, 2010 11:15 am    Post subject: Reply with quote

Dive into Python wrote:
Python functions have no explicit begin or end, and no curly braces to mark where the function code starts and stops. The only delimiter is a colon (Smile and the indentation of the code itself.


Ref: http://book.opensourceproject.org.cn/lamp/python/diveintopython/index.html

Indenting is a structural requirement of Python syntax.
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8452
Location: Warrington, UK

PostPosted: Sun May 16, 2010 12:39 pm    Post subject: Reply with quote

LeeNukes wrote:
While on the theme of Python, why are indents such an issue? I used to think they were just to make it easy for people to read, but it stops a program working if they are slightly wrong.


Because indentation is part of the syntax, it does the job of braces in most other languages. You'd expect a syntax error from a missing brace in them, you get the same from a missing tab in Python, for exactly the same reasons.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
cbuffer



Joined: Thu Nov 01, 2007 12:04 am
Posts: 67

PostPosted: Sun May 16, 2010 5:18 pm    Post subject: Reply with quote

graemef wrote:
The L indicates that the data type is a Long integer. The second version which prints the value converts the numeric to a character string and the data type is not shown.


Thank you graemef, I really should have worked that out for myself.

Ken
Back to top
View user's profile Send private message
LeeNukes
LXF regular


Joined: Sun Jun 21, 2009 9:11 pm
Posts: 954
Location: At the bar

PostPosted: Sun May 16, 2010 6:39 pm    Post subject: Reply with quote

nelz wrote:
LeeNukes wrote:
While on the theme of Python, why are indents such an issue? I used to think they were just to make it easy for people to read, but it stops a program working if they are slightly wrong.


Because indentation is part of the syntax, it does the job of braces in most other languages. You'd expect a syntax error from a missing brace in them, you get the same from a missing tab in Python, for exactly the same reasons.


at least braces are visible though. Trying to work out which indent needs to line up with which isn't straight forward.
_________________
Join GiffGaff and get 5 free credit
Back to top
View user's profile Send private message
JPGargoyle



Joined: Fri Jul 29, 2005 12:29 am
Posts: 20

PostPosted: Sun May 16, 2010 6:50 pm    Post subject: Reply with quote

LeeNukes wrote:

at least braces are visible though. Trying to work out which indent needs to line up with which isn't straight forward.


How can you say that?

If you don't know what must be lined up, then you don't know what you are programming.
If you are writing a python (or any other) program, it's you who know it's logical structure, so for example you should know all the code that must be executed inside an if statement for your program to work. If that block of code must be inside braces, or equally indented, it's exactly the same.

Best regards
Back to top
View user's profile Send private message
LeeNukes
LXF regular


Joined: Sun Jun 21, 2009 9:11 pm
Posts: 954
Location: At the bar

PostPosted: Sun May 16, 2010 7:04 pm    Post subject: Reply with quote

JPGargoyle wrote:
LeeNukes wrote:

at least braces are visible though. Trying to work out which indent needs to line up with which isn't straight forward.


How can you say that?

If you don't know what must be lined up, then you don't know what you are programming.
If you are writing a python (or any other) program, it's you who know it's logical structure, so for example you should know all the code that must be executed inside an if statement for your program to work. If that block of code must be inside braces, or equally indented, it's exactly the same.

Best regards


This was someone elses code I was trying to get to work. I sorted it in the end, but I had to mess with the indents,
_________________
Join GiffGaff and get 5 free credit
Back to top
View user's profile Send private message
JPGargoyle



Joined: Fri Jul 29, 2005 12:29 am
Posts: 20

PostPosted: Sun May 16, 2010 7:14 pm    Post subject: Reply with quote

LeeNukes wrote:

This was someone elses code I was trying to get to work. I sorted it in the end, but I had to mess with the indents,


Ah, that's the major point on python's indenting: posting code online, copy-pasting it, leaving to situations where white-spacing and formatting is lost. But that's no reason to change one of the (IMHO) best features of python.

Best regards
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast