Skip to content

Commit

Permalink
Merge branch 'master' into duck-typing-python
Browse files Browse the repository at this point in the history
  • Loading branch information
lpozo authored Feb 9, 2024
2 parents 113db69 + f25d2ed commit 76458ce
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python-bnf-notation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# BNF Notation: Dive Deeper Into Python's Grammar

This folder provides the code examples for the Real Python tutorial [BNF Notation: Dive Deeper Into Python's Grammar](https://realpython.com/python-bnf-notation/).
10 changes: 10 additions & 0 deletions python-bnf-notation/conditional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def read_temperature():
return 25


if (temperature := read_temperature()) < 10:
print("The weather is cold!")
elif 10 <= temperature <= 25:
print("The weather is nice!")
else:
print("The weather is hot!")
5 changes: 5 additions & 0 deletions python-bnf-notation/func_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def func():
return


print(func())
5 changes: 5 additions & 0 deletions python-bnf-notation/func_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def func():
return "Hello!"


func()
5 changes: 5 additions & 0 deletions python-bnf-notation/func_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def func():
return "Hello!", "Pythonista!"


func()
5 changes: 5 additions & 0 deletions python-bnf-notation/func_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def func():
return ("Hello!",)


func()
8 changes: 8 additions & 0 deletions python-bnf-notation/func_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def func():
return (
"Hello!",
"Pythonista!",
)


func()
8 changes: 8 additions & 0 deletions python-bnf-notation/loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
high = 5

for number in range(high):
if number > 5:
break
print(number)
else:
print("range covered")
3 changes: 3 additions & 0 deletions python-bnf-notation/walrus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(length := len([1, 2, 3]))

print(length)

0 comments on commit 76458ce

Please sign in to comment.