Sunday, July 17, 2011

Indentation in Python

hai... meet me again... now, i'm still learning python , i think it's great to learn python it's little bit different with java or c++, but i still love python because i can use my logic there... of course it's programming dude ^_^ like just what i say, it's little bit different with another programming language, but so far i get something new, what is that? it is indentation.... now, i try to explain what is that indentation....( actually, i just get from the book :D) Whitespace is important in Python. Actually, whitespace at the beginning of the line is important. This is called indentation. Leading whitespace (spaces and tabs) at the beginning of the logical line is used to determine the indentation level of the logical line, which in turn is used to determine the grouping of statements. For example: When you run this, you get the following error: Notice that there is a single space at the beginning of the second line. The error indicated by Python tells us that the syntax of the program is invalid i.e. the program was not properly written. What this means to you is that you cannot arbitrarily start new blocks of statements. and actually how to indent ... Do not use a mixture of tabs and spaces for the indentation as it does not work across different platforms properly. I strongly recommend that you use a single tab or two or four spaces for each indentation level. Choose any of these three indentation styles. More importantly, choose one and use it consistently i.e. use that indentation style only. yeah, that's it , i think that is clear , if there are any question... dont hestitate to call me... ^_^ and the book is : A Byte of Python - Swaroop C H

No comments:

Post a Comment