Francais

Francais


Home


Products


Download


Tutorials

    Python Section
  • Python Quick Reference

  • Web Ring/Links


    Contact

    Block iterative or block conditional

    As other programming language Python can manage conditional or iterative code, but it does not have special characters to identify them. Only the indent identifies a block. Two characters are allowed, the space and the tabulation. However, all the lines in a block must be indent in the same way. Because, use a tabulation is not equal to the number equivalent of spaces. Remark: a block in the interpreter must finish by an empty line. A blocks inside a Python script have not such limitation.The real examples of indentation are in the chapter while.

    Examples :
    Tabulation Spaces Mix
    >>>def fct(A) :
    …   [tab] print a
    …   [tab] return a

    >>> print fct(5)
    5
    >>>def fct(A) :
    …      print a
    …      return a

    >>> print fct(5)
    5
    >>>def fct(A) :
    …  [ tab] print a
    …       return a
    unindent does not match any outer indentation level

    Conditions

    There is the table of arithmetic or string condition to create conditional block.
     Non boolean conditions
    Equal = = Different !=
    Lesser < Greater >
    Lesser or equal <= Greater or equal >=
    Boolean conditions
    is
    equal if A is True: return True
    in
    inside if A in ('y','yes') : return True

    while

    Allow looping on a counter variable basis.

    Examples :
    Test 1 Test 2
    >>> A=0
    >>> while A<3 :
    …      A+=1
    …      print A

    1
    2
    3
    >>> A=0
    >>> while A<3 :
    …       A+=1

    >>> print A
    3
    Test with a line of code Syntaxe of Test 2 in a script
    >>> A=0
    >>> while a<3:
    …     A+=1

    >>> print A
    3
    >>> A=0
    >>>while A<3 :
    …    A+=1

    >>> print A



    Previous Page
    7/13

    Next Page