Skip to content

Commit

Permalink
Added more examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Egges authored and ABDreos committed Sep 10, 2024
1 parent 273d382 commit 0734fbc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 2024/weird_things/class_members.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class X:
some_attribute = 1


def main() -> None:
a = X()
b = X()
print(a.some_attribute)
print(b.some_attribute)
X.some_attribute = 2
print(a.some_attribute)
print(b.some_attribute)
a.some_attribute = 3
print(a.some_attribute)
print(b.some_attribute)
print(X.some_attribute) # what will this print?


if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions 2024/weird_things/class_members_dataclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from dataclasses import dataclass


@dataclass
class X:
some_attribute: int = 1


def main() -> None:
a = X()
b = X()
print(a.some_attribute)
print(b.some_attribute)
X.some_attribute = 2
print(a.some_attribute)
print(b.some_attribute)
a.some_attribute = 3
print(a.some_attribute)
print(b.some_attribute)
print(X.some_attribute) # what will this print?


if __name__ == "__main__":
main()
9 changes: 9 additions & 0 deletions 2024/weird_things/reference_inconsistency.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
def f():
return 1


def main() -> None:
print(f()) # Output: 1
a = [1, 2, 3]
b = a # b is now a reference to a
print(id(a))
print(id(b))
a += [4]
print(b) # Output: [1, 2, 3, 4]

s = "hello"
t = s # t is now a reference to s
print(id(s))
print(id(t))
s += " world"
print(t) # Output: "hello"

Expand Down
16 changes: 16 additions & 0 deletions 2024/weird_things/return_after.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def f():
return 1
console.log("hello world")


# def g():
# return 1
# std::cout << "hello world" << std::endl


def main() -> None:
f()


if __name__ == "__main__":
main()

0 comments on commit 0734fbc

Please sign in to comment.