Introduction in Python

Python syntax

ecu.test has been implemented in the Python script language. User inputs such as formulas, logical operations etc. must be made in Python syntax. To make the start easier for users without knowledge of Python, the following table summarizes possible operators.

Name of operation

Python syntax

Example

Comments

addition

+

X + Y

subtraction

-

X - Y

multiplication

*

X * Y

division

/

X / Y

Returns a float.

power

**

X ** Y

remainder / modulo

%

X % Y

remainder of integer division

floor division

//

X // Y

Rounds off all digits. If both operands are integers, the result also is.

bracketing

( )

(X + Y) * Z

Expressions in brackets are computed first, otherwise multiplication and division take precedence over addition and subtraction.

logical “AND” (conjunction)

and

X and Y

Returns True or False.

logical “OR” (disjunction)

or

X or Y

Returns True or False.

logical “NOT” (negation)

not

not X

bitwise “AND”

&

X & Y

bitwise “OR”

|

X | Y

bitwise “XOR” (exclusive OR)

^

X ^ Y

bitwise “NOT”

~

~ X

bitshift left

<<

X << Y

bitshift right

>>

X >> Y

less than

<

X < Y

Returns True or False.

greater than

>

X > Y

Returns True or False.

less or equal

<=

X <= Y

Returns True or False.

greater or equal

>=

X >= Y

Returns True or False.

equal

==

X == Y

Returns True or False.

not equal

!=

X != Y

Returns True or False.

Python data types

ecu.test uses the following data types to represent the values that occur in the test cases:

  • numbers

    • integers (int) in decimal representation

      1234, 1234567890546378940

    • integers (int) in octal representation

      0o177, 0O17777777777777777 (leading 0o or 0O, case insensitive)

    • integers (int) in hexadecimal representation

      0xFF, 0XFFFFffffFFFFFFFF (prefix 0x or 0X, case insensitive)

    • integers (int) in binary representation

      0b11, 0B101010 (leading 0b or 0B, case insensitive)

    • floating-point numbers (float)

      3.14e-10, 0.001, 10.0, 1E3 (decimal point, e or E for powers of 10)

    • complex numbers (complex)

      1J, 2+3J, 4+5j (real and imaginary part separated by +, both as float, imaginary unit j or J)

  • sequences

    • character sequences / strings

      '', '1', "12", 'hello\n', 'hello\x0a' (in single or double quotes, \n for newline, \t for TAB, double backslash \\ for single \, unprintable characters in hex representation \x..)

    • tuples

      (), (1,), (1,2) (tuples of length 1 need an additional comma to distinguish them from bracketed expressions)

    • lists

      [], ['a'], [5, 'hello']

    • indexed access

      0-based index, negative indices count from the end, subsequences with [from:up to before]

      examples:

      • a = (0,1,2,3,4,5,6,7)

      • a[3] == 3

      • a[-1] == 7

      • a[2:4] == (2,3)

      • a[1:] == (1,2,3,4,5,6,7)

      • a[:3] == (0,1,2)

      • a[:] == (0,1,2,3,4,5,6,7) (copy of a)


  • dictionaries (mappings)

    pairs key : value, between curly braces {}

    access with [key ]:

    • d1 = {} (empty mapping)

    • d2 = {1: "entry 1"}

      • d2[1] == "Eintrag 1"

    • d3 = {'text': 'some text', 'number': 3}

      • d3['text'] == 'some text'

      • d3['number'] == 3

Python documentation

Further information towards Python can be found in the official Python documentation.

To download the documentation use the following link (Internet required): Download Python Documentation.