Skip to content

Commit 854450d

Browse files
Static typing and closures
1 parent 8e2ba48 commit 854450d

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
# Virtual environments
55
venv
6+
7+
# Cache
8+
platzi/advanced/.mypy_cache

platzi/advanced/closures.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from timeit import repeat
2+
3+
4+
def make_repeater_of(n: int) -> object:
5+
def repeater(word: str) -> object:
6+
assert isinstance(word, str), "You must use a string"
7+
return word * n
8+
9+
return repeater
10+
11+
12+
def main():
13+
repeat_5 = make_repeater_of(5)
14+
print(repeat_5("Hello"))
15+
16+
repeat_10 = make_repeater_of(10)
17+
print(repeat_10("Platzi"))
18+
19+
20+
if __name__ == "__main__":
21+
main()

platzi/advanced/palindrome.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def is_palindrome(word: str) -> bool:
2+
replaced_word = word.replace(" ", "").lower()
3+
return replaced_word == word[::-1]
4+
5+
6+
def main():
7+
palindrome = is_palindrome(100)
8+
print(palindrome)
9+
10+
11+
if __name__ == "__main__":
12+
main()

platzi/oop/polymorphism.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Person:
2+
23
def __init__(self, name: str) -> None:
34
self.name = name
45

@@ -7,9 +8,10 @@ def advance(self) -> None:
78

89

910
class Cyclist(Person):
11+
1012
def __init__(self, name: str) -> None:
1113
super().__init__(name)
12-
14+
1315
def advance(self) -> None:
1416
print("Riding on my bike...")
1517

0 commit comments

Comments
 (0)