Differences between revisions 3 and 4
Revision 3 as of 2008-04-13 11:38:40
Size: 520
Editor: anonymous
Comment:
Revision 4 as of 2008-04-13 12:27:08
Size: 1309
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
= Variable names =
Allowed names for identifier (name of variable or function):
 * Any sequence of alphabetical character, number, or underline character {{{_}}}
 * First symbol has to be a character
 * Case sensitive
 * Not a python built-in keyword

== Name space ==

The Python interpreter maps the name of an identifier in the active name space. The active name space depends on the active code block (module, function). The identifier can be local or global with respect to the active code block.

{{{#!python
def bad_style(x):
 # Name space of bad_style
 global y
 y=x
 z=x
 return x

# Name space of __main__
x,y,z=2,2,2
x=bad_style(1)
print 'x=',x,'y=',y,'z=',z
# y is changed!
}}}
Line 10: Line 36:
== Scalar/Number == == Scalar ==
Line 17: Line 43:

=== Casting ===

 * int()
 * long()
 * float()
 * complex()
 * str()

Variable names

Allowed names for identifier (name of variable or function):

  • Any sequence of alphabetical character, number, or underline character _

  • First symbol has to be a character
  • Case sensitive
  • Not a python built-in keyword

Name space

The Python interpreter maps the name of an identifier in the active name space. The active name space depends on the active code block (module, function). The identifier can be local or global with respect to the active code block.

   1 def bad_style(x):
   2         # Name space of bad_style
   3         global y
   4         y=x 
   5         z=x
   6         return x
   7 
   8 # Name space of __main__
   9 x,y,z=2,2,2
  10 x=bad_style(1)
  11 print 'x=',x,'y=',y,'z=',z
  12 # y is changed!

Built-in

Scalar

  • Plain integer: 9

  • Long integer: 9**99, 1L

  • Hex integer: 0x10

  • Floating point: 0.1

  • Exponential floating point: 1e-3

  • Complex: 3+2j

Casting

  • int()
  • long()
  • float()
  • complex()
  • str()

Sequences

String

Tuple

List

Dictionary

Extended data types

Array

Copy and reference

LehreWiki: SiaProgrammingPythonDatatypes (last edited 2008-04-13 17:13:34 by anonymous)