The Python Apprentice
eBook - ePub

The Python Apprentice

Robert Smallshire, Austin Bingham

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

The Python Apprentice

Robert Smallshire, Austin Bingham

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Learn the Python skills and culture you need to become a productive member of any Python project.About This Book• Taking a practical approach to studying Python• A clear appreciation of the sequence-oriented parts of Python• Emphasis on the way in which Python code is structured• Learn how to produce bug-free code by using testing toolsWho This Book Is ForThe Python Apprentice is for anyone who wants to start building, creating and contributing towards a Python project. No previous knowledge of Python is required, although at least some familiarity with programming in another language is helpful.What You Will Learn• Learn the language of Python itself• Get a start on the Python standard library• Learn how to integrate 3rd party libraries• Develop libraries on your own• Become familiar with the basics of Python testingIn DetailExperienced programmers want to know how to enhance their craft and we want to help them start as apprentices with Python. We know that before mastering Python you need to learn the culture and the tools to become a productive member of any Python project. Our goal with this book is to give you a practical and thorough introduction to Python programming, providing you with the insight and technical craftsmanship you need to be a productive member of any Python project. Python is a big language, and it's not our intention with this book to cover everything there is to know. We just want to make sure that you, as the developer, know the tools, basic idioms and of course the ins and outs of the language, the standard library and other modules to be able to jump into most projects.Style and approachWe introduce topics gently and then revisit them on multiple occasions to add the depth required to support your progression as a Python developer. We've worked hard to structure the syllabus to avoid forward references. On only a few occasions do we require you to accept techniques on trust, before explaining them later; where we do, it's to deliberately establish good habits.

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 The Python Apprentice als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu The Python Apprentice von Robert Smallshire, Austin Bingham im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Informatik & Programmierung in Python. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2017
ISBN
9781788298667

Exploring Built-in Collection types

We've already encountered some of the built-in collections
  • str – the immutable string sequence of Unicode code points
  • list – the mutable sequence of objects
  • dict – the mutable dictionary mapping from immutable keys to mutable
    objects
We've only scratched the surface of how these collections work, so we'll explore their powers in greater depth in this chapter. We'll also introduce three new built-in collections types:
  • tuple - the immutable sequence of objects
  • range - for arithmetic progressions of integers
  • set - a mutable collection of unique, immutable objects
We won't cover the bytes type any further here. We've already discussed its essential differences with str, and most of what we learn about str can also be applied to bytes.
This is not an exhaustive list of Python collection types, but it's completely sufficient for the overwhelming majority of Python 3 programs you'll encounter in the wild or are likely to write yourself.
In this chapter we'll be covering these collections in the order mentioned above, rounding things off with an overview of the protocols that unite these collections and which allow them to be used in consistent and predictable ways.

tuple – an immutable sequence of objects

Tuples in Python are immutable sequences of arbitrary objects. Once created, the objects within them cannot be replaced or removed, and new elements cannot be added.

Literal tuples

Tuples have a similar literal syntax to lists, except that they are delimited by parentheses rather than square brackets. Here is a literal tuple containing a string, a float and an integer:
>>> t = ("Norway", 4.953, 3)
>>> t
('Norway', 4.953, 3)

Tuple element access

We can access the elements of a tuple by zero-based index using square brackets:
>>> t[0]
'Norway'
>>> t[2]
3

The length of a tuple

We can determine the number of elements in the tuple using the built-in len() function:
>>> len(t)
3

Iterating over a tuple

We can iterate over it using a for-loop:
>>> for item in t:
>>> print(item)
Norway
4.953
3

Concatenating and repetition of tuples

We can concatenate tuples using the plus operator:
>>> t + (338186.0, 265E9)
('Norway', 4.953, 3, 338186.0, 265000000000.0)
Similarly, we can repeat them using the multiplication operator:
>>> t * 3
('Norway', 4.953, 3, 'Norway', 4.953, 3, 'Norway', 4.953, 3)

Nested tuples

Since tuples can contain any object, it's perfectly possible to have nested tuples:
>>> a = ((220, 284), (1184, 1210), (2620, 2924), (5020, 5564), (6232, 6368))
We use repeated application of the indexing operator to get to the inner elements:
>>> a[2][1]
2924

Single-element tuples

Sometimes a single element tuple is required. To write this, we can't just use a simple object in parentheses. This is because Python parses that as an object enclosed in the precedence controlling parentheses of a math expression:
>>> h = (391)
>>> h
391
>>> type(h)
<class 'int'>
To create a single-element tuple we make use of the trailing comma separator which, you'll recall, we're allowed to use when specifying literal tuples, lists, and dictionaries. A single element with a trailing comma is parsed as a single element tuple:
>>> k = (391,)
>>> k
(391,)
>>> type(k)
<class 'tuple'>

Empty tuples

This leaves us with the problem of how to specify...

Inhaltsverzeichnis