Prev: Namespaces and Modules | Next: Where do types come from?
- (a) Acceptable names consist of: (underscore or letter) + (any number of letters, digits or underscores)
- (b) Names are case sensitive: 'spam' is different from 'Spam' and different from 'SPAM'
# Assignment examples
a = b = c = 0 # all names are bound to value object '0'
a, b = 1, 1.5 # a is bound to 1, b to 1.5
a, b, c = 'foo' # equivalent to: a='f', b='o', c='o'
a, b, c = (1,2,3) # equivalent to: a=1, b=2, c=3
a, b, *c = 'spam' # equivalent to: a='s', b='p', c=['a','m']
a, b = b, a # swapping values
x = 'Hello world!'
print(type(x), len(x))
x = 1
print(type(x), len(x))
... on the contrary requires that:
- (a) The types of variable names are declared before any assignment.
- (b) The values given to variables during runtime are of the type declared in the beginning of the program.
Thus, a program in C could start like this:
/* variable definition: */
int a, b;
/* assignment */
a = 10;
b = 20;
. Free learning material
. See full copyright and disclaimer notice