Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien
logo-home
Summary 'Automate The Boring Stuff with Python' for Information & Data Management €6,49
Ajouter au panier

Resume

Summary 'Automate The Boring Stuff with Python' for Information & Data Management

 0 fois vendu
  • Cours
  • Établissement
  • Book

English summary of all the required chapters of 'How to automate the boring stuff with Python' by Al Sweigart, ISBN: 97815 . Includes chapter 1-5 of the book and Jake Vanderplas: The Basics of NumPy Arrays. For the course Information & Data Management of the BSc Business Administration at the UvA

Aperçu 3 sur 21  pages

  • Non
  • 1-5
  • 7 février 2023
  • 21
  • 2019/2020
  • Resume
avatar-seller
Python

Chapter 1: Python Basics
The interactive shell, also called the REPL (Read-Evaluate-Print Loop), lets you run (or execute)
Python instructions one at a time and instantly shows you the results.

Expressions consist of values (such as 2) and operators (such as +), and they can always evaluate
(reduce) down to a single value. Therefore, you can use expressions anywhere in Python code that
you could also use a value. An example of an expression is 2+2, which can be evaluated down to the
value 4. A single value with no operators is also considered an expression, though it evaluates only to
itself. E.g., the value 4 is also considered an expression.
Table 1 shows all math operators in Python:




The order of operations (precedence) of Python math operators is similar to that of mathematics:
The ** operator is evaluated first, followed by the *, /, //, and % operators from left to right, and
finally the + and – are evaluated from left to right. Parentheses can be used to override this
precedence. Whitespace in between the operators and values does not matter for Python, although
a single space is contention. The programmer must enter the expression, but Python will keep
evaluating parts until it becomes a single value.

A data type is a category for values, where every value belongs to one data type. Table 2 shows the
most common data types. Note that 1 is an integer (int), while 1.0 is a floating-point number (floats)
because it incorporates a decimal point. Strings are text values surrounded by single quote (‘)
characters, also known as strs (pronounce: stirs). A string with no characters in it (‘’) is called an
empty/blank string. If you see the error message SyntaxError: EOL while scanning string literal, you
probably forgot the final single quote character at the end of the string.

,The meaning of an operator depends on the data types of the values next to it. E.g., + is the addition
operator when it operates on 2 integers or floating-point values, but when used on 2 string values it
joins the strings as the string concatenation operator:
>>> ‘Alice’ + ‘Bob’
OUTPUT: ‘AliceBob’

However, if you try to use the + operator on a string and an integer value, Python will an error:
>>> ‘Alice’ + 42
Traceback (most recent call last):
File “<pyshell#0>”, line 1, in <module>
‘Alice’ + 42
TypeError: can only concatenate str (not “int”) to str
This means that Python thought you were trying to concatenate an integer to the string ‘Alice’. Your
code will have to explicitly convert the integer to a string because Python cannot do this
automatically.

The * operator multiplies 2 integer or floating-point values. When used on one string value and one
integer value, it becomes the string replication operator, evaluating the expression down to a single
string value that repeats the original string a number of times equal to the integer value.
>>> ‘Alice’ * 5
‘AliceAliceAliceAliceAlice’
The * operator can only be used with 2 numeric values or one string and one integer value. Python
cannot multiply words with words or words with a floating-point value.

If you want to use the result of an evaluated expression later in your program, you can save it inside
a variable: a box in the computer’s memory where you can store a single value. You can store values
in variables with an assignment statement consisting of a variable name, an equal sign (the
assignment operator), and the value to be stored. E.g. spam = 40 is a variable named spam with
the integer value 40 stored in it.
A variable is initialized (created) the first time a value is stored in it. After that, you can use it in
expressions with other variables and values.
>>> spam = 40
>>> spam
40
>>> eggs = 2
>>> spam + eggs
42
When a variable is assigned a new value, the old value is forgotten. This is called overwriting the
variable.
>>> spam = ‘Hello’
>>> spam
‘Hello’
>>> spam = ‘Goodbye’
>>> spam
‘Goodbye’

A good variable name describes the data it contains. It may not contain spaces, it cannot begin with a
number, and it can only use letters, numbers, and the underscore (_) character. No other special
characters are allowed. Variable names are case-sensitive, meaning that spam and Spam will be
different variables. Variables are usually started with a lowercase letter. Instead of underscores, you
can also use camelcase, meaning that every new word starts with a capitalized letter. E.g.,

, current_balance becomes currentBalance.




The interactive shell is used to run Python instructions one at a time, but to write entire programs,
the file editor is used. In the file editor, instructions will not be run when you press enter. Instead,
you can save a file with many instructions and then run the program. In addition, it does not have the
>>> prompt. You can start the program in the file editor so that it will start running in the interactive
shell. When there are no more lines of code to execute, the Python program terminates (stops
running/exits).

An example of a program, including explanation per line:
# This program says hello and asks for my name.
Every line following a hash mark (#) is called a comment and will be ignored by Python. It can be used
as a note to yourself. The # can also be used to temporarily remove a line of code while testing a
program. This is called commenting out and can be useful if you want to find out why your program
does not work.
print(‘Hello, world!’)
print(‘What is your name?’) # ask for their name
The function print() indicates that Python has to print out the text in the string, e.g. Hello, world!
When Python executes this line, it is calling the print() function and the string value is being passed
to the function. A value that is passed to a function call is an argument. You need to use parentheses
after a function name to identify it as the name of a function.
myName = input()
The input() function waits for to send some text. This function call evaluates to a string equal to the
user’s text, and the line of code assigns the myName variable to this string value.
print(‘It is good to meet you,’ + myName)
This expression will evaluate to a single string value that can be passed to print().
print(‘The length of your name is:’)
print(len(myName))
The len() function evaluates to the integer value of the number of characters in a string value. It is
then passed to print() to be displayed on the screen, which only allows you to pass it either integer
values or string values. Therefore you will get an error if you combine string values with an integer,
e.g. if you try:

Les avantages d'acheter des résumés chez Stuvia:

Qualité garantie par les avis des clients

Qualité garantie par les avis des clients

Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.

L’achat facile et rapide

L’achat facile et rapide

Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.

Focus sur l’essentiel

Focus sur l’essentiel

Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.

Foire aux questions

Qu'est-ce que j'obtiens en achetant ce document ?

Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.

Garantie de remboursement : comment ça marche ?

Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.

Auprès de qui est-ce que j'achète ce résumé ?

Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur bergceline1. Stuvia facilite les paiements au vendeur.

Est-ce que j'aurai un abonnement?

Non, vous n'achetez ce résumé que pour €6,49. Vous n'êtes lié à rien après votre achat.

Peut-on faire confiance à Stuvia ?

4.6 étoiles sur Google & Trustpilot (+1000 avis)

69252 résumés ont été vendus ces 30 derniers jours

Fondée en 2010, la référence pour acheter des résumés depuis déjà 15 ans

Commencez à vendre!
€6,49
  • (0)
Ajouter au panier
Ajouté