Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions basics/call_external_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def main() -> None:
"""
>>> import subprocess
>>> _ = subprocess.run(["ls", "-l"])
"""


if __name__ == "__main__":
from doctest import testmod

testmod()
12 changes: 12 additions & 0 deletions basics/log_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def main() -> None:
import logging

logging.debug("Debugging information")
logging.info("Informational message")
logging.warning("Warning:config file %s not found", "server.conf")
logging.error("Error occurred")
logging.critical("Critical error -- shutting down")


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions basics/sets_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def main() -> None:
"""
>>> languages = {"Python", "Java", "C", "JavaScript", "Python", "C"}
>>> len(languages)
4
>>> "Java" in languages
True
>>> "Python" in languages
True
>>> "c" in languages
False
"""


if __name__ == "__main__":
from doctest import testmod

testmod()
22 changes: 22 additions & 0 deletions maths/to_integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def to_integer(number_str: str) -> int:
"""
>>> to_integer("123")
123
>>> to_integer("3.14")
3
>>> to_integer("-123")
-123
>>> to_integer("-3.14")
-3
>>> to_integer("123a")
Traceback (most recent call last):
...
ValueError: could not convert string to float: '123a'
"""
return int(float(number_str))


if __name__ == "__main__":
from doctest import testmod

testmod()
20 changes: 20 additions & 0 deletions strings/contains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def contains(main_str: str, sub_str: str) -> bool:
"""
>>> "a" in "abc"
True
>>> "bc" in "abc"
True
>>> "ac" in "abc"
False
>>> "" in "abc"
True
>>> "" in ""
True
"""
return sub_str in main_str


if __name__ == "__main__":
from doctest import testmod

testmod()