[course]07 —— 面向对象编程 01
1. Methods vs Functions
s = 'This could be any string!'
print(len(s)) # len is a function
print(s.upper()) # upper is a string method, called using the . notation
# we say that we "call the method len on the string s"
print(s.replace('could', 'may')) # some methods take additional argumentsn = 123
print(len(n)) # TypeError: object of type 'int' has no len()
# This means that len() cannot work properly with int's
n = 123
print(n.upper()) # AttributeError: 'int' object has no attribute 'upper'
# This means that there is no method upper() for int's2. Classes and Instances
3. Objects and Object-Oriented Programming (OOP)
Last updated