Syntax

The syntax of the Python programming language is the set of rules which defines how a Python program will be written. Python Line Structure:
A Python program is divided into a number of logical lines and every logical line is terminated by the token NEWLINE.
A logical line is created from one or more physical lines.
A line contains only spaces, tabs, formfeeds possibly a comment, is known as a blank line, and Python interpreter ignores it.
A physical line is a sequence of characters terminated by an end-of-line sequence (in windows it is called CR LF or return followed by a linefeed and in Unix, it is called LF or linefeed).
See the following example.

1.|x = 4
2.|if (x > 0):
3.|
4.|
5.|    print("hello world")
6.|    # hello world

Basic Syntax for Print. ( indentation is very Important )

print("hello world.")

Basic Syntax for ( if ) statement. ( indentation is very Important )

if ( condition ):
    ## code here
    print("Anything.")

Basic Syntax for ( if and else ) statement. ( indentation is very Important )

if ( condition ):
    ## code exicuted when if condition is true
    print("Anything.")
else:
    ## code exicuted when if condition is false
    print("Anything.")

Basic Syntax for ( if , elif and else ) statement. ( indentation is very Important )

if ( condition ):
    ## code exicuted when if condition is true
    print("Anything.")
elif ( condition ):
    ## code exicuted when elif condition is true
    print("anything")
else:
    ## code exicuted when if and elif conditions are false
    print("Anything.")

Basic Syntax for Nested ( if ) statement. ( indentation is very Important )

if ( condition ):
    ## code exicuted when if condition is true
    print("Anything.")
    if ( condition ):
        ## code exicuted when both the if conditions are true
        print("anything")
    else:
        ## code exicuted when the first (if) condition is true and second (if) condition is false
        print("anything")
else:
    ## code exicuted when first (if) condition is false
    print("Anything.")

Basic Syntax for ( for loop ) statement. ( indentation is very Important )

for i in range(10):
    print(i)
    ## here (i) is a varible starts from 0 to range.

Basic Syntax for ( while loop ) statement. ( indentation is very Important )

while ( condition ): 
    print("anything") 
    ## code exicuted when while condition is true
    ( code ) ## write an increment or decrement statement to break while loop

Basic Syntax for ( for loop with else ) statement. ( indentation is very Important )

for i in range(10):
    print(i)
    ## here (i) is a varible starts from 0 upto range.
else:
    ## code exicuted when ( for loop ) ends
    print("anything after for loop")

Basic Syntax for ( while loop with else ) statement. ( indentation is very Important )

while ( condition ): 
    print("anything")
    ## code exicuted when while condition is true
    ( code ) ## write an increment or decrement statement to break while loop
else:
    ## code exicuted when while condition is false
    print("anything after while loop")

Basic Syntax for ( Nested loop and If ) statement. ( indentation is very Important )

for i in range(123):
    if ( condition ):
        print("exicuted when if condition is true")
    else:
        print("exicuted when if condition is false")
while ( condition ):
    if ( condition ):
        print("exicuted when if condition is true")
    elif ( condition ):
        print("exicuted when elif condition is true")
    else:
        print("exicuted when both conditions are false")
    ( code ) ## code to break the while loop

Basic Syntax for ( Nested loop in loop ) statement. ( indentation is very Important )

for i in range(123):
    for j in range(5):
        print(i,j)


while ( condition ):
    while ( condition ):
        print("exicuted when ( while ) condition is true")
        ( code ) ## code to break the while loop
    else:
        print("exicuted when ( while ) condition is false")
    ( code ) ## code to break the while loop
else:
    print("code exicuted when while condition is false")