Expert Python Programming
eBook - ePub

Expert Python Programming

Master Python by learning the best coding practices and advanced programming concepts, 4th Edition

Michał Jaworski, Tarek Ziadé

  1. 630 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Expert Python Programming

Master Python by learning the best coding practices and advanced programming concepts, 4th Edition

Michał Jaworski, Tarek Ziadé

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Gain a deep understanding of building, maintaining, packaging, and shipping robust Python applications

Key Features

  • Discover the new features of Python, such as dictionary merge, the zoneinfo module, and structural pattern matching
  • Create manageable code to run in various environments with different sets of dependencies
  • Implement effective Python data structures and algorithms to write, test, and optimize code

Book Description

This new edition of Expert Python Programming provides you with a thorough understanding of the process of building and maintaining Python apps. Complete with best practices, useful tools, and standards implemented by professional Python developers, this fourth edition has been extensively updated. Throughout this book, you'll get acquainted with the latest Python improvements, syntax elements, and interesting tools to boost your development efficiency.

The initial few chapters will allow experienced programmers coming from different languages to transition to the Python ecosystem. You will explore common software design patterns and various programming methodologies, such as event-driven programming, concurrency, and metaprogramming. You will also go through complex code examples and try to solve meaningful problems by bridging Python with C and C++, writing extensions that benefit from the strengths of multiple languages. Finally, you will understand the complete lifetime of any application after it goes live, including packaging and testing automation.

By the end of this book, you will have gained actionable Python programming insights that will help you effectively solve challenging problems.

What you will learn

  • Explore modern ways of setting up repeatable and consistent Python development environments
  • Effectively package Python code for community and production use
  • Learn modern syntax elements of Python programming, such as f-strings, enums, and lambda functions
  • Demystify metaprogramming in Python with metaclasses
  • Write concurrent code in Python
  • Extend and integrate Python with code written in C and C++

Who this book is for

The Python programming book is intended for expert programmers who want to learn Python's advanced-level concepts and latest features.

Anyone who has basic Python skills should be able to follow the content of the book, although it might require some additional effort from less experienced programmers. It should also be a good introduction to Python 3.9 for those who are still a bit behind and continue to use other older versions.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Expert Python Programming als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Expert Python Programming von Michał Jaworski, Tarek Ziadé im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Ciencia de la computación & Programación en Python. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

4

Python in Comparison with Other Languages

Many programmers come to Python with prior experience of other programming languages. It happens often that they are already familiar with programming idioms of those languages and try to replicate them in Python. As every programming language is unique, bringing such foreign idioms often leads to overly verbose or suboptimal code.
The classic example of a foreign idiom that is often used by inexperienced programmers is iteration over lists. Someone that is familiar with arrays in the C language could write Python code similar to the following example:
for index in range(len(some_list)): print(some_list[index]) 
An experienced Pythonic programmer would most probably write:
for item in some_list: print(item) 
Programming languages are often classified by paradigms that can be understood as cohesive sets of features supporting certain "styles of programming." Python is a multiparadigm language and thanks to this, it shares many similarities with a vast amount of other programming languages. As a result, you can write and structure your Python code almost the same way you would do that in Java, C++, or any other mainstream programming language.
Unfortunately, often that won't be as effective as using well-recognized Python patterns. Knowing native idioms allows you to write more readable and efficient code.
This chapter is aimed at programmers experienced with other programming languages. We will review some of the important features of Python together with idiomatic ways of solving common problems. We will also see how these compare to other programming languages and what common pitfalls are lurking for seasoned programmers that are just starting their Python journey. Along the way, we will cover the following topics:
  • Class model and object-oriented programming
  • Dynamic polymorphism
  • Data classes
  • Functional programming
  • Enumerations
Let's begin by considering the technical requirements.

Technical requirements

The code files for this chapter can be found at https://github.com/PacktPublishing/Expert-Python-Programming-Fourth-Edition/tree/main/Chapter%204.

Class model and object-oriented programming

The most prevalent paradigm of Python is object-oriented programming (also known as OOP). It is centered around objects that encapsulate data (in the form of object attributes) and behavior (in the form of methods). OOP is probably one of the most diverse paradigms. It has many styles, flavors, and implementations that have been developed over many years of programming history. Python takes inspiration from many other languages, so in this section, we will take a look at the implementation of OOP in Python through the prism of different languages.
To facilitate code reuse, extensibility, and modularity, OOP languages usually provide a means for either class composition or inheritance. Python is no different and like many other object-oriented languages supports the subclassing of types.
Python may not have as many object-oriented features as other OOP languages, but it has a pretty flexible data and class model that allows you to implement most OOP patterns with extreme elegance. Also, everything in Python is an object, including functions and class definitions and basic values like integers, floats, Booleans, and strings.
If we would like to find another popular programming language that has similar object-oriented syntax features and a similar data model, one of the closest matches would probably be Kotlin, which is a language that runs (mostly) on Java Virtual Machine (JVM). The following are the similarities between Kotlin and Python:
  • A convenient way to call methods of super-classes: Kotlin provides the super keyword and Python provides the super() function to explicitly reference methods or attributes of super-classes.
  • An expression for object self-reference: Kotlin provides the this expression, which always references the current object of the class. In Python, the first argument of the method is always an instance reference. By convention, it is named self.
  • Support for creating data classes: Like Python, Kotlin provides data classes as "syntactic sugar" over classic class definitions to simplify the creation of class-based data structures that are not supposed to convey a lot of behavior.
  • The concept of properties: Kotlin allows you to define class property setters and getters as functions. Python provides the property() decorator with a similar purpose, together with the concept of descriptors, which allows you to fully customize the attribute access of an object.
What makes Python really stand out in terms of OOP implementation is the approach to inheritance. Python, unlike Kotlin and many other languages, freely permits multiple inheritance (although it often isn't a good idea). Other languages often do not allow this or provide some constraints. Another important Python differentiator is the lack...

Inhaltsverzeichnis

  1. Preface
  2. Current Status of Python
  3. Modern Python Development Environments
  4. New Things in Python
  5. Python in Comparison with Other Languages
  6. Interfaces, Patterns, and Modularity
  7. Concurrency
  8. Event-Driven Programming
  9. Elements of Metaprogramming
  10. Bridging Python with C and C++
  11. Testing and Quality Automation
  12. Packaging and Distributing Python Code
  13. Observing Application Behavior and Performance
  14. Code Optimization
  15. Other Books You May Enjoy
  16. Index
Zitierstile für Expert Python Programming

APA 6 Citation

Jaworski, M., & Ziadé, T. (2021). Expert Python Programming (4th ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/2664302/expert-python-programming-master-python-by-learning-the-best-coding-practices-and-advanced-programming-concepts-4th-edition-pdf (Original work published 2021)

Chicago Citation

Jaworski, Michał, and Tarek Ziadé. (2021) 2021. Expert Python Programming. 4th ed. Packt Publishing. https://www.perlego.com/book/2664302/expert-python-programming-master-python-by-learning-the-best-coding-practices-and-advanced-programming-concepts-4th-edition-pdf.

Harvard Citation

Jaworski, M. and Ziadé, T. (2021) Expert Python Programming. 4th edn. Packt Publishing. Available at: https://www.perlego.com/book/2664302/expert-python-programming-master-python-by-learning-the-best-coding-practices-and-advanced-programming-concepts-4th-edition-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Jaworski, Michał, and Tarek Ziadé. Expert Python Programming. 4th ed. Packt Publishing, 2021. Web. 15 Oct. 2022.