Home
Products
Download
Tutorials
Web Ring/Links
Contact
|
String variableA string variable is created when the assigned value is between ' (quote) or " (double-quote) or by using the str() function.
Examples : >>> A="String" >>> print A String | >>> A='String' >>> print A String | >>> A=str(56) >>> print A+"Toto" 56Toto | Special characters as carriage return starts by a \ (backslash).
Examples : >>> A="First line\nSecond line" >>> print A First line Second line | >>> A="First line\\nSecond line" >>> print A First line\nSecond line | When a value contains special characters
and they cannot be interpreted, it is better to use raw mode assignment. That is donne, by adding the letter r in lowercase
before the value.
Examples : >>> A=r"First line\nSecond line" >>> print A First line\nSecond line | >>> A=r"First line\\nSecond line" >>> print A First line\\nSecond line | List variable
A
list is an array of elements indexed from zero. It can mix different types
of element. Even, a list's element can be another list.
Examples : >>> liste=[ "chaîne", 2.0,3 ]
>>> print liste
['cha\x8cne', 2.0, 3] >>> print liste[0] chaîne
| >>> list=[1,2,3]
>>> list1=[list, 4, [ 5, 6] ]
>>> print list1
[[1, 2, 3], 4, [5, 6]] | Remark: This example was intentionally left in French to shows a string containing international characters.Special variable _ (Underscore)This variable contains always the last value computed. It is really useful when the interpreter is used as calculator. Remark: This special feature will be lost if this variable receives a value.
Examples : Without _ | With _ | >>>5+10 15 >>>15/3 5 | >>>5+10 15 >>>_/3 5 |
|
|