tailieunhanh - PROGRAMMING IN PYTHON 3 - PART 5

Tham khảo tài liệu 'programming in python 3 - part 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 236 Chapter 6. Object-Oriented Programming appropriate to our class. This will ensure that we never get conflicts with later versions of Python even if they introduce new predefined special methods. Objects usually have attributes methods are callable attributes and other attributes are data. For example a complex object has imag and real attributes and lots of methods including special methods like_add__ andsub_ to support the binary and - operators and normal methods like conjugate . Data attributes often referred to simply as attributes are normally implemented as instance variables that is variables that are unique to a particular object. We will see examples of this and also examples of how to provide data attributes as properties. A property is an item of object data that is accessed like an instance variable but where the accesses are handled by methods behind the scenes. As we will see using properties makes it easy to do data validation. Inside a method which is just a function whose first argument is the instance on which it is called to operate several kinds of variables are potentially accessible. The object s instance variables can be accessed by qualifying their name with the instance itself. Local variables can be created inside the method these are accessed without qualification. Class variables sometimes called static variables can be accessed by qualifying their name with the class name and global variables that is module variables are accessed without qualification. Some of the Python literature uses the concept of a namespace a mapping from names to objects. Modules are namespaces for example after the statement import math we can access objects in the math module by qualifying them with their namespace name . and . Similarly classes and objects are also namespaces for example if we have z complex 1 2 the z object s namespace has two attributes which we can access and . One of the advantages of object .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.