You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-2Lines changed: 66 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1672,6 +1672,7 @@ The immutable data types are:
1672
1672
String
1673
1673
Bool
1674
1674
Tuple
1675
+
Frozenset
1675
1676
1676
1677
You can usually use the function hash() to check an object mutability, if it is hashable it is immutable, although this does not always work as intended as user defined objects might be mutable and hashable
1677
1678
</b></details>
@@ -1760,7 +1761,70 @@ There is a more advanced python feature called MetaClasses that aid the programm
1760
1761
</b></details>
1761
1762
1762
1763
<details>
1763
-
<summary>What is an exception? What types of exceptions are you familiar with?</summary><br><b>
1764
+
<summary> What is an error? What is an exception? What types of exceptions are you familiar with?</summary><br><b>
1765
+
1766
+
```
1767
+
1768
+
# Note that you generally don't need to know the compiling process but knowing where everything comes from
1769
+
# and giving complete answers shows that you truly know what you are talking about.
1770
+
1771
+
Generally, every compiling process have a two stops.
1772
+
- Analysis
1773
+
- Code Generation.
1774
+
1775
+
Analysis can be broken into:
1776
+
1. Lexycal analysis (Tokenizes source code)
1777
+
2. Syntactic analysis (Check whether the tokens are legal or not, tldr, if syntax is correct)
1778
+
1779
+
for i in 'foo'
1780
+
^
1781
+
SyntaxError: invalid syntax
1782
+
1783
+
We missed ':'
1784
+
1785
+
1786
+
3. Semantic analysis (Contextual analysis, legal syntax can still trigger errors, did you try to divide by 0,
1787
+
hash a mutable object or use an undeclared function?)
1788
+
1789
+
1/0
1790
+
ZeroDivisionError: division by zero
1791
+
1792
+
These three analysis steps are the responsible for error handlings.
1793
+
1794
+
The second step would be responsible for errors, mostly syntax errors, the most common error.
1795
+
The third step would be responsible for Exceptions.
1796
+
1797
+
As we have seen, Exceptions are semantic errors, there are many builtin Exceptions:
1798
+
1799
+
ImportError
1800
+
ValueError
1801
+
KeyError
1802
+
FileNotFoundError
1803
+
IndentationError
1804
+
IndexError
1805
+
...
1806
+
1807
+
You can also have user defined Exceptions that have to inherit from the `Exception` class, directly or indirectly.
1808
+
1809
+
Basic example:
1810
+
1811
+
class DividedBy2Error(Exception):
1812
+
def __init__(self, message):
1813
+
self.message = message
1814
+
1815
+
1816
+
def division(dividend,divisor):
1817
+
if divisor == 2:
1818
+
raise DividedBy2Error('I dont want you to divide by 2!')
1819
+
return dividend / divisor
1820
+
1821
+
division(100, 2)
1822
+
1823
+
>>> __main__.DividedBy2Error: I dont want you to divide by 2!
1824
+
1825
+
```
1826
+
1827
+
1764
1828
</b></details>
1765
1829
1766
1830
<details>
@@ -2151,7 +2215,7 @@ func main() {
2151
2215
</summary><br><b>
2152
2216
2153
2217
It looks what unicode value is set at 101 and uses it for converting the integer to a string.
2154
-
If you want to get "101" you should use the package "strconv" and repalce <code>y = string(x)</code> with <code>y = strconv.Itoa(x)</code>
2218
+
If you want to get "101" you should use the package "strconv" and replace <code>y = string(x)</code> with <code>y = strconv.Itoa(x)</code>
0 commit comments