tailieunhanh - Lecture Programming languages (2/e): Chapter 13d - Tucker, Noonan

Chapter 13d - Python. Many authors view Python as an object-oriented language. However, your authors have the somewhat broader view that Python is a multiparadigrn language supporting the following programming styles: Imperative, object-oriented, functional. In this sense, Python is closer to C++ (which is also multiparadigm) than it is to Srnalltalk. | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents Prelude: Abstract Data Types The Object Model Smalltalk Java Python Python Multiparadigm Imperative Object-orientd Functional Scripting language Dynamically typed General Characteristics Builtin types: int, float, infinite precision integers, complex numbers, strings, . Data structure Lists: [1, [2, "allen"], "bob", ] Hashes: ["Tucker": "Bowdoin", "Noonan": "W&M"] Tuples: (238111, "allen", "bob") Strings: viewed as list of characters List operators work on strings Python "less forgiving" than Perl Cannot do string operations on numbers Or vice versa Cannot index past end of list Must append to end of a list Statements fairly conventional Indentation used for compound statements No $var as in Perl (bareword error) Reference semantics used for assignment Multiple inheritance All methods and instance variables are public. Variables must be set before being referenced. Run time type identification Reflection Examle: Polynomials Represent Polynomials: 3 x2 + 5x - 7 Representation: #(-7 5 3) Subclass of Magnitude class Polynomial: def __init__(self, coef): """constructor""" = [ ] + coef def degree(self): """Highest power with a non-zero coefficient""" return len(coefficient) def coefficient(self, power): """Coefficient of given power""" if power > len(coefficient): return 0 return coefficient[power] def asList(self): """return copy of coefficient""" return [ ] + coefficient def __eq__(self, aPoly): """return self == aPoly""" return coefficient == ( ) def __ne__(self, aPoly): """return self ( )""" return coefficient ( ) def __str__(self): """return string representation""" r = "" p = len(coefficient) + 1 while p > 0: p = p - 1 if . | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents Prelude: Abstract Data Types The Object Model Smalltalk Java Python Python Multiparadigm Imperative Object-orientd Functional Scripting language Dynamically typed General Characteristics Builtin types: int, float, infinite precision integers, complex numbers, strings, . Data structure Lists: [1, [2, "allen"], "bob", ] Hashes: ["Tucker": "Bowdoin", "Noonan": "W&M"] Tuples: (238111, "allen", "bob") Strings: viewed as list of characters List operators work on strings Python "less forgiving" than Perl Cannot do string operations on numbers Or vice versa Cannot index past end of list Must append to end of a list Statements fairly conventional Indentation used for compound statements No $var as in Perl (bareword error)

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.