User Tools

Site Tools


script:walkthrough:basic_expressions

This is an old revision of the document!


Basic expressions

Basic types

All numbers are internally stored as 64-bit floats.

$ print 5, 5.5, -3.141592657
5 5.5 -3.14159

Hexadecimal numbers use the “0x” prefix.

$ print 0x100, 0X123
256 291

Underscores can be inserted in numbers at any points. This is only to improve readability for humans; the parser ignores them.

$ print 'Underscores for readability: %x' % 0x0012_3456
Underscores for readability: 0x123456

Text strings can use single, double, or triple quotes. Single and double are semantically equal. C-like escape sequences are supported, for example \n for a newline. Triple-quoted strings can contain newlines without having to escape them with a backslash.

$ print "Hello", 'World'
Hello World

$ print """I can span
newlines."""
I can span
newlines.

Arrays are created using brackets around comma-separated elements.

$ print [1, 2, 3]
[ 1, 2, 3 ]

The elements of arrays can be of any type.

$ print [1, [2, 3], 4]
[ 1, [ 2, 3 ], 4 ]

Dictionaries contain key-value pairs. A dictionary is created with curly brackets.

$ print {'a': 10, 'b': 5}
{ a: 10, b: 5 }

Both the key and the value can be of any type.

$ print {'a': 'b', 1: ['b', {5:6, 6:7}], ['array', 'as', 'key']: 'oh my'}
{ 1: [ b, { 5: 6, 6: 7 } ], [ array, as, key ]: oh my, a: b }

Time values store a specific point in time. The built-in function Time() returns the current local time.

$ print 'The time is now:', Time()
The time is now: 2019-11-19 21:33:16.501

Constants

Commonly used constants have reserved keywords.

$ print True, False, None, Pi
True False (none) 3.14159

Built-in functions

  • Built-in functions: len(), dictkeys(), dictvalues().
  • Built-in functions: Text(), Number().
  • Built-in functions: serialize() and deserialize().
script/walkthrough/basic_expressions.1574193592.txt.gz · Last modified: 2019-11-19 21:59 by skyjake