print(list())
# chuỗi nguyên âm
nguyenamString = 'aeiou'
print(list(nguyenamString))
# tuple nguyên âm
# viết bởi TipsMake.com
nguyenamTuple = ('a', 'e', 'i', 'o', 'u')
print(list(nguyenamTuple))
# danh sách nguyên âm
nguyenamList = ['a', 'e', 'i', 'o', 'u']
print(list(nguyenamList))
Run the program, the result is:
[]
['a', 'e', 'i', 'o', 'u']
['a', 'e', 'i', 'o', 'u']
['a', 'e', 'i', 'o', 'u']
# set nguyên âm
nguyenamSet = {'a', 'e', 'i', 'o', 'u'}
print(list(nguyenamSet))
# dictionary nguyên âm
nguyenamDictionary = {'a': 1, 'e': 2, 'i': 3, 'o':4, 'u':5}
print(list(nguyenamDictionary))
Running the program results in:
['e', 'o', 'a', 'i', 'u']
['e', 'o', 'u', 'a', 'i']
class PowTwo:
def __init__(self, max):
self.max = max
def __iter__(self):
self.num = 0
return self
def __next__(self):
if(self.num >= self.max):
raise StopIteration
result = 2 ** self.num
self.num += 1
return result
powTwo = PowTwo(5)
powTwoIter = iter(powTwo)
print(list(powTwoIter))
Running the program results in:
[1, 2, 4, 8, 16]
See also: Built-in Python functions