Exemplo n.º 1
0
print a[1:3]  # Slicing

b = {}  # Empty dictionary

# Dictionary with strings and numbers as indices
b = {"a": 1, "b": 2, 1: "x", 2: "y", "-test-": 1 + 2, "0HAY0": "a" + "B"}

# Accessing subscript (simple string)
print b["a"]

# Accessing subscript (other string; assignment)
b["-test-"] = 3

# Accessing subscript (number)
print b[1]

# Deleting from map
del b["a"]

# Modulo operator on strings, i.e. sprintf
print "Demo %d %s %.2f" % (b["-test-"], "abc", 0.123456)

# Operator precedence test
print(1 > 2) and ((2 * 3) > 8)  # removes all parentheses
print 1 * (2 + 4) * -(1 + 2)  # keeps all parentheses
print(True and True) and False or False

# isinstance
print isinstance([], list)
print isinstance(Hash(), Hash)