# Simple arithmetic
>>> 1 / 2
0.5
>>> 2 ** 3
8
>>> 17 / 3 # true division returns a float
5.666666666666667
>>> 17 // 3 # floor division
5
Intuitive Divination
Calculations are simple with the serpent's tongue, and its grammar is unnervingly straightforward: the sigils +, -, * and / work exactly as foretold; parentheses () bind a working into groups.
# Python 3: List comprehensions
>>> specters = ['Banshee', 'Wraith', 'Ghoul']
>>> wailing = [s.upper() for s in specters]
>>> print(wailing)
['BANSHEE', 'WRAITH', 'GHOUL']
>>> list(enumerate(specters))
[(0, 'Banshee'), (1, 'Wraith'), (2, 'Ghoul')]
Compound Familiars
Lists — known as arrays to lesser tongues — are one of the compound forms the serpent understands. They can be indexed, sliced, and bent to your will with built-in rites.
# For loop on a list
>>> numbers = [2, 4, 6, 8]
>>> product = 1
>>> for number in numbers:
... product = product * number
...
>>> print('The curse multiplies to:', product)
The curse multiplies to: 384
The Expected Flow
The serpent knows the usual rites of control that other tongues speak — if, for, while and range — each carrying its own unsettling twist.
# Python 3: Fibonacci series up to n
>>> def haunt(n):
... a, b = 0, 1
... while a < n:
... print(a, end=' ')
... a, b = b, a + b
... print()
>>> haunt(144)
0 1 1 2 3 5 8 13 21 34 55 89
Functions Defined
The heart of extensible sorcery is defining functions. The serpent allows mandatory and optional arguments, keyword offerings, and even arbitrary argument lists.
# Simple output (with Unicode)
>>> print("Hello, I haunt in Python!")
Hello, I haunt in Python!
>>> name = input('Who disturbs my rest?\n')
>>> print(f'Beware, {name}.')
Who disturbs my rest? Traveler
Beware, Traveler.
Quick to Learn
Practitioners of any other tongue can pick up the serpent's speech swiftly, and novices find its clean grammar and indentation easy to master, even by candlelight.