Data Types in Python
Text Type: | str |
Numeric Types: | int , float , complex |
Sequence Types: | list , tuple , range |
Mapping Type: | dict |
Set Types: | set , frozenset |
Boolean Type: | bool |
Binary Types: | bytes , bytearray , memoryview |
None Type: | NoneType |
Generator
- generator is a function that returns an iterator that produces a sequence of values when iterated over. Generators are useful when we want to produce a large sequence of values, but we don't want to store all of them in memory at once.
def my_generator(n):
# initialize counter
value = 0
# loop until counter is less than n
while value < n:
# produce the current value of the counter
yield value
# increment the counter
value += 1# iterate over the generator object produced by my_generator
for value in my_generator(3):
# print each value produced by generator
print(value)
Immutable / Mutable data types
Mutable: list, sets, and dictionary
Immutable: int, str, bool, float, tuple
Комментариев нет:
Отправить комментарий