Built-in Data Types
Category | Types |
---|---|
Numeric | int, float, complex |
String | str |
Sequence | list, tuple, range |
Binary | bytes, bytearray |
Mapping | dict |
Boolean | bool |
Set | set, frozenset |
# int
x = 58
# float
x = 5.8
# complex
x = 5 + 8j
# string
x = "Hello Literank!"
# list
x = ["lite", "rank", "hello"]
# tuple
x = ("li", "te", "rank")
# range
x = range(58)
# dict
x = {"key1": "lite", "key2": "rank"}
# set
x = {"lite", "rank"}
y = set(['a', 'b', 'c'])
z = set("literank")
# frozenset
x = frozenset({"lite", "rank"})
# bool
x = False
# bytes
x = b"literank"
y = bytes.fromhex('2Ef0 F1f2')
# bytearray
x = bytearray(3)
y = bytearray.fromhex('2Ef0 F1f2')
print(x, y)
Try to click the ▶ Run button to see the output in the right. And try to comment/uncomment some lines to see different data types.
The elements of a set must be hashable. To represent sets of sets, the inner sets must be frozenset objects.
Bytes objects are immutable sequences of single bytes, while bytearray objects are mutable, they support the mutable sequence operations in addition to the common bytes operations.
Code Challenge
Try to modify the code provided in the editor to make it print
{'a': ['c', 'a'], 'b': b'.\xf0\xf1\xf2'}
.
Loading...
> code result goes here