#0003 really simple command line arguments management
#!/usr/bin/env python3
#Purpose: Say hello
import argparse
parser = argparse.ArgumentParser(description='Say Hello')
parser.add_argument('name',help='Name to greet')
args = parser.parse_args()
print('Hello, ' + args.name + '!')
#0002 (tiny python projects)
- keywords = [ pytest, black/yapf, flake8/pylint, new.py ]
- python3 -m pip install black flake8 ipython mypy pylint pytest yapf
#0001
#!/usr/local/bin/python3.7
#playing with yield (generators)
def infinite_sequence():
num = 0
while True:
yield num
num += 1
#Question: Why does this not work?
result=next(infinite_sequence())
print(result)
result=next(infinite_sequence())
print(result)
result=next(infinite_sequence())
print(result)
#But this does ...
for item in infinite_sequence():
print(f"{item}")
print("\n")
- Comprehensions: list, set, and dictionary comprehensions
- Generator expressions
- Generator functions:
Generator functions use the Python yield keyword instead of return.