Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types

Bop is dynamically typed — variables can hold any type, and types are checked at runtime. There are six types:

TypeLiteralsExamples
numberDigits, optional decimal0, 42, -7, 3.14
stringDouble-quoted"hello", "got {n} items"
boolKeywordstrue, false
noneKeywordnone
arraySquare brackets[1, 2, 3], []
dictCurly braces with colons{"x": 10, "name": "Alice"}

You can check a value’s type at runtime with the type() function:

let x = 42
print(type(x))    // "number"

let s = "hello"
print(type(s))    // "string"

Numbers

Bop has a single number type (64-bit floating point internally). Whole numbers display without a decimal point: 5 not 5.0.

let score = 100
let pi = 3.14
let negative = -7

Division always produces a float result:

print(7 / 2)     // 3.5
print(6 / 2)     // 3

Use int() to truncate the decimal part:

print(int(7 / 2))   // 3
print(int(3.9))      // 3

Strings

Strings use double quotes only. Supported escape sequences: \", \\, \n, \t, \{, \}.

let greeting = "Hello, world!"
let with_newline = "Line 1\nLine 2"

Strings are indexable and iterable, but immutable — you can read characters but not change them in place:

let s = "hello"
print(s[0])     // "h"
print(s[-1])    // "o"

for ch in s {
  print(ch)     // "h", "e", "l", "l", "o"
}

String interpolation

Use {variable} inside a string to insert a variable’s value. Only variable names are allowed inside {} — not expressions:

let name = "Alice"
let count = 5
print("Hello, {name}! You have {count} items.")

For computed values, store the result in a variable first:

let doubled = str(count * 2)
print("Double: {doubled}")

// Or use concatenation:
print("Double: " + str(count * 2))

To include a literal { or } in a string, escape it with a backslash:

print("Use \{name\} for interpolation")
// prints: Use {name} for interpolation

Booleans

true and false. Used in conditions and comparisons:

let found = true
let empty = false

if found {
  print("Got it!")
}

None

none represents the absence of a value. Functions that don’t explicitly return a value return none. It’s also what you get when looking up a missing dictionary key:

let stats = {"hp": 10}
let missing = stats["armor"]
print(missing)    // none