The Python Apprentice
eBook - ePub

The Python Apprentice

Robert Smallshire, Austin Bingham

Partager le livre
  1. 352 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

The Python Apprentice

Robert Smallshire, Austin Bingham

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que The Python Apprentice est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  The Python Apprentice par Robert Smallshire, Austin Bingham en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Informatik et Programmierung in Python. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2017
ISBN
9781788298667
Édition
1

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...

Table des matiĂšres