Skip to content

Commit

Permalink
Merge pull request #58 from freekie224/patch-1
Browse files Browse the repository at this point in the history
Update classes.ipynb
  • Loading branch information
jonas-eschle authored Apr 17, 2023
2 parents d854542 + ac56a07 commit 0ac6675
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions python/classes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"\n",
"In programming, classes, or more general OOP (Object Oriented Programing) is a fundamental paradigm (next to others, e.g. functional programming). It is powerful and e.g. Java is fully based on it. Python is a multi-paradigm (and multi-everything anyway) language, meaning there are classes, functions etc.\n",
"\n",
"However, classes play in Python an extremely important role - although one does not directly has to no about it - since actually every object in Python \"comes from a class\". But we're going ahead of things.\n",
"However, classes play in Python an extremely important role - although one does not directly have to know about it - since actually every object in Python \"comes from a class\". But we're going ahead of things.\n",
"\n",
"Let's start with an example problem"
]
Expand All @@ -18,7 +18,7 @@
"metadata": {},
"source": [
"We want to do some calculations with particles and their momenta, e.g. to calculate their invariant mass.\n",
"(we focus on just one paricle here, sure we could use lists but this means to keep track of which entry is which etc.)"
"(we focus on just one particle here, sure we could use lists but this means to keep track of which entry is which etc.)"
]
},
{
Expand Down Expand Up @@ -59,7 +59,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Alright, but clearly cumbersom. Better: if we could stick it together. Let's use a dict!"
"Alright, but clearly cumbersome. Better: if we could stick it together. Let's use a dict!"
]
},
{
Expand Down Expand Up @@ -310,31 +310,31 @@
"Exercise: override the `__add__` method to make two particle addable. Name it `Particle`\n",
"Hint: you need to construct a new Particle\n",
"\n",
"STOP SCROLING, SOLUTION AHEAD!\n",
"STOP SCROLLING, SOLUTION AHEAD!\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"STOP SCROLING, SOLUTION AHEAD!\n",
"STOP SCROLLING, SOLUTION AHEAD!\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"STOP SCROLING, SOLUTION AHEAD!\n",
"STOP SCROLLING, SOLUTION AHEAD!\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"STOP SCROLING, SOLUTION AHEAD!"
"STOP SCROLLING, SOLUTION AHEAD!"
]
},
{
Expand Down Expand Up @@ -405,7 +405,7 @@
"class VerboseParticle(Particle): # This is inheritance\n",
" \n",
" def momentum_text(self):\n",
" return f\"px: {self.px}, py: {self.py}, pz {self.pz}\"\n",
" return f\"px: {self.px}, py: {self.py}, pz: {self.pz}\"\n",
" "
]
},
Expand Down Expand Up @@ -458,7 +458,7 @@
"\n",
"(Sidenote: be aware of `isinstance` vs `type`, use the former if not explicitly type has to be used.)\n",
"\n",
"So we can replace the call in `__add__` as follows. Insead of\n",
"So we can replace the call in `__add__` as follows. Instead of\n",
"```return Particle(new_px, new_py, new_pz, new_E)```\n",
"we have\n",
"```return type(self)(new_px, new_py, new_pz, new_E)```\n",
Expand Down

0 comments on commit 0ac6675

Please sign in to comment.