Wiki

Changes between Version 1 and Version 2 of ExpressionTour

Show
Ignore:
Timestamp:
06/20/10 04:12:38 (14 years ago)
Author:
Chuck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExpressionTour

    v1 v2  
    11= Expression Tour = 
    22 
    3 This is a "tour" of various kinds of expressions in Cobra. It is not a reference manual for expressions, but is instead intended to help you learn Cobra. 
     3This is a "tour" of various kinds of expressions in Cobra. It is intended to help you learn Cobra by quickly highlighting some interesting expressions you can write. It is neither a reference nor an exhaustive list of features. It assumes that the reader has basic familiarity with programming. 
    44 
    55== Displaying Expression Values == 
     
    1616 
    1717You can, of course, use a [wiki:Print] statement. On a related note, you can validate the value of an expression with an [wiki:Assert] statement. 
     18{{{ 
     19#!python 
     20print 'My name is', name 
     21assert x > 0 
     22}}} 
     23 
     24== Arithmetic == 
     25 
     26Arithmetic has the usual infix operators and parentheses for grouping. Note that division with a single slash (/) gives a fractional value. Use a double slash (//) for "integer" division. 
     27{{{ 
     28#!python 
     29assert 4 / 5 = 0.8 
     30assert 4 // 5 == 0 
     31assert 6 / 5 == 1.2 
     32assert 6 // 5 == 1 
     33}}} 
     34 
     35Augmented assignment operators can be used to change values: 
     36{{{ 
     37#!python 
     38i += 1 
     39p.x *= 2 
     40}}} 
     41 
     42Underscores can be put in numbers to separate groups of digits for easier reading: 
     43{{{ 
     44#!python 
     45big = 10_000_000 
     46}}}