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
@@ -1581,6 +1590,20 @@ import math # this is math.py because it have higher priority
1581
1590
print(math.add(1, 2))
1582
1591
```
1583
1592
1593
+
#### Built-in modules
1594
+
1595
+
There are several built-in modules in Python, which you can import whenever you like, you can find them in here: https://docs.python.org/3/py-modindex.html
1596
+
1597
+
```python
1598
+
import platform
1599
+
import math
1600
+
import io
1601
+
1602
+
print(platform.system())
1603
+
print(math.sqrt(12))
1604
+
print(io.open("contacts.txt").readline())
1605
+
```
1606
+
1584
1607
### Classes
1585
1608
1586
1609
Python is an Object Oriented Programming language.
student_tuan.welcome() # Welcome Kim Phuong to the class A3
1761
1784
```
1762
1785
1763
-
#### Class access control
1786
+
#### Access Modifiers
1764
1787
1765
1788
Python supports a form of access control for class properties and methods, although it does so in a more informal way compared to some other languages like Java or C++.
1766
1789
@@ -1811,9 +1834,10 @@ Python use naming conventions to indicate the intended level of access:
1811
1834
obj.access_protected()
1812
1835
1813
1836
# example 02
1814
-
# we still able to access private attributes and methods but will breaks the encapsulation principle
1815
-
# by using mangled name
1816
-
# Not recommended to use this way.
1837
+
# Python doesn't block access to private data, it just leaves for the wisdom of the programmer,
1838
+
# not to write any code that access it from outside the class.
1839
+
# You can still access the private attributes/methods by Python's name mangling technique
1840
+
# but will breaks the encapsulation principle so not recommend to do this in real-life
1817
1841
classSubClass(MyClass):
1818
1842
defaccess_protected(self):
1819
1843
print(self._MyClass__private_var) # I am protected
0 commit comments