Francais

Francais


Home


Products


Download


Tutorials

    Python Section
  • Python Quick Reference

  • Web Ring/Links


    Contact

    Basic operations

    The basic operations are the addition +, the subtraction -, the multiplication * and the division /. The string variables can only added or multiplied.

    Examples :
    Numeral String
    >>> B=3
    >>> C=2
    >>> A=B+C
    >>> print A
    5
    >>> A=B+C*2+B
    >>> print A
    10
    >>> B="toto"
    >>> C="titi"
    >>> A=B+C
    >>> print A
    tototiti
    >>> A=B+C*2+B
    >>> print A
    tototititititoto

    Basic operations in abbreviated syntax

    If a formula change only the value of a variable. There are two syntax's possible, the normal and the short. The last one is write, variable name follow by the operation,  the equal sign and finally the formula.

    Examples:

    Normal Short
    >>> A=3
    >>> B=2
    >>> A=A+B
    >>> print A
    5
    >>> A=3
    >>> B=2
    >>> A+=B
    >>> print A
    5

    Strings operations

    A string is a characters array indexed from zero. The array syntax must used to get one or more characters. So variable[FirstChar:LastChar]. The first character of the string will assume if FirstChar was omitting. If the LastChar was omitting, the string's extraction will goes to the end. If only one index is use, only one character will extracted.

    Examples:

    >>> a="Hello"
    >>> print a[2:4]
    ll
    >>> # Shows the two first characters.
    >>> print a[:2]
    He
    >>> # Shows the string from the third character.
    >>> print a[2:] 
    llo
    >>> # Shows the fifth character.
    >>> print a[4]
    o
    A string variable can only be assigned or used. It is not possible to modify partially its contents. So replace a character is only possible by assigns a whole string to the variable.

    Examples :
    Bad Correct
    >>> A="Hello"
    >>> A[2]="z"
    object doesn't support item assignment
    >>> A="Hello"
    >>> A=A[:2]+"z"+A[3:]
    >>> print A
    Hezlo



    Previous Page
    5/13

    Next Page