• Mauvais document ? Échangez-le gratuitement
  • Rédigé par des étudiants ayant réussi
  • Disponible immédiatement après paiement
  • Lire en ligne ou en PDF
Vendre
Où étudie-tu ?
La langue
Document preview thumbnail
Aperçu 4 sur 304 pages
Presentation

Think Python, 3rd Edition

Document preview thumbnail
Aperçu 4 sur 304 pages

"Python is an excellent way to get started in programming, and this clear, concise guide walks you through Python a step at a time—beginning with basic programming concepts before moving on to functions, data structures, and object-oriented design. This revised third edition reflects the growing role of large language models (LLMs) in programming and includes exercises on effective LLM prompts, testing code, and debugging skills. With this popular hands-on guide at your side, you'll get: A grounding in the syntax and semantics of the Python language A clear definition of each programming concept, with emphasis on clear vocabulary How to work with variables, statements, functions, and data structures in a logical progression Techniques for reading and writing files and databases A solid understanding of objects, methods, and object-oriented programming Debugging strategies for syntax, runtime, and semantic errors An introduction to recursion, interface design, data structures, and basic algorithms How to use LLMs—including effective prompts, testing code, and debugging And more"

Aperçu du contenu

,Chapter 1. Programming as a Way of
Thinking
The first goal of this book is to teach you how to program in Python. But learning to program
means learning a new way to think, so the second goal of this book is to help you think like a
computer scientist. This way of thinking combines some of the best features of mathematics,
engineering, and natural science. Like mathematicians, computer scientists use formal languages
to denote ideas—specifically computations. Like engineers, they design things, assembling
components into systems and evaluating trade-offs among alternatives. Like scientists, they
observe the behavior of complex systems, form hypotheses, and test predictions.

We will start with the most basic elements of programming and work our way up. In this chapter,
we’ll see how Python represents numbers, letters, and words. And you’ll learn to perform
arithmetic operations.

You will also start to learn the vocabulary of programming, including terms like operator,
expression, value, and type. This vocabulary is important—you will need it to understand the rest
of the book, to communicate with other programmers, and to use and understand virtual assistants.


Arithmetic Operators
An arithmetic operator is a symbol that represents an arithmetic computation. For example, the
plus sign, +, performs addition:


30 + 12


42


The minus sign, –, is the operator that performs subtraction:


43 - 1


42


The asterisk, *, performs multiplication:


6 * 7

,42


And the forward slash, /, performs division:





42.0


Notice that the result of the division is 42.0 rather than 42. That’s because there are two types of
numbers in Python:

 integers, which represent whole numbers, and
 floating-point numbers, which represent numbers with a decimal point.

If you add, subtract, or multiply two integers, the result is an integer. But if you divide two integers,
the result is a floating-point number. Python provides another operator, //, that performs integer
division. The result of integer division is always an integer:


84 // 2


42


Integer division is also called “floor division” because it always rounds down (toward the “floor”):


85 // 2


42


Finally, the operator ** performs exponentiation; that is, it raises a number to a power:


7 ** 2


49


In some other languages, the caret, ^, is used for exponentiation, but in Python it is a bitwise
operator called XOR. If you are not familiar with bitwise operators, the result might be unexpected:

, 7 ^ 2


5


I won’t cover bitwise operators in this book, but you can read about them
at http://wiki.python.org/moin/BitwiseOperators.


Expressions
A collection of operators and numbers is called an expression. An expression can contain any
number of operators and numbers. For example, here’s an expression that contains two operators:


6 + 6 ** 2


42


Notice that exponentiation happens before addition. Python follows the order of operations you
might have learned in a math class: exponentiation happens before multiplication and division,
which happen before addition and subtraction.

In the following example, multiplication happens before addition:


12 + 5 * 6


42


If you want the addition to happen first, you can use parentheses:


(12 + 5) * 6


102


Every expression has a value. For example, the expression 6 * 7 has the value 42.


Arithmetic Functions

Infos sur le Document

Publié le
9 août 2024
Nombre de pages
304
Écrit en
2017/2018
Type
Presentation
Personne
Inconnu
$5.49

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Vendu
0
Abonnés
0
Éléments
225
Dernière vente
-



Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Vous travaillez sur vos références ?

Créez des citations précises en APA, MLA et Harvard avec notre générateur de sources gratuit.

Vous travaillez sur vos références ?

Foire aux questions