Basic Rules To Follow While Writing Python Code

<b>First:</b> Python keywords are very basic at the stage of learning this scripting language. These are most commonly and frequently used while coding.
Purpose of each keyword is known clearly while applying it in programming.

and     lambda   not
assert  continue or
break  for           pass
class   yield        print
finally global     except
del      if             with
while  import     try
elif      in           def
else     is            return
raise   exec        from

<b>Second:</b> Indentation is really interesting thing in python. This is optional and nice to have indented code blocks in other programming languages.
Whereas in python this is mandatory, otherwise the program execution is failed. At various steps indentation is required like after conditional statements, functions, modules etc. Error condition triggered without indentation is shown below.

>>> if x &gt; y:
... print "x is greater"
  File "<stdin>", line 2
    print "x is greater"
        ^
IndentationError: expected an indented block

<b>Third:</b> String assignment is done using "equal to" or = operator. But the string text is defined in single, double and triple quotes. One example can give a better picture.

>>> x = 'python'
>>> y = "Python2"
>>> z = """Python3"""
>>> x
'python'
>>> y
'Python2'
>>> z
'Python3'
>>>

No comments:

Post a Comment

Featured Post

Introduction To Groovy Programming

Starting with the first program printing "Hello World". There is no interactive shell available like other scripting langugages t...