Information & Data Management: SUMMARY Automate The Boring Stuff with Python
186 views 10 purchases
Course
Information and Data Management
Institution
Universiteit Van Amsterdam (UvA)
Book
Automate the Boring Stuff with Python
English summary for the course Information & Data Management of the bachelor Business Administration at the UvA. It includes all the required chapters of 'How to automate the boring stuff with Python' and some additional lecture notes. If you read this you will understand Python and programming way...
Totale samenvatting vak programming (800863-M-3)
Summary 'Automate The Boring Stuff with Python' for Information & Data Management
All for this textbook (3)
Written for
Universiteit van Amsterdam (UvA)
Business Administration
Information and Data Management
All documents for this subject (17)
Seller
Follow
chiara-uva
Reviews received
Content preview
AUTOMATE THE BORING STUFF:
/ CH1 /
A window with the >>> prompt should appear; that’s the interactive shell.
2 + 2 is called an expression: consist of values (such as 2) and operators (such as +),
and they can always evaluate (that is, reduce) down to a single value.
** Exponent 2 ** 3 8
% Modulus/remainder 22 % 8 6
// Integer division/floored quotient 22 // 8 2
Modules/Remainder: divides by whole number (22-(2x8)=6)
Integer division: divides by whole number and deletes any decimals. 22//8=2.75 → = 2
Precedence: the order of operations: ** , *, /, //, % , +, - . Use parentheses ( ) [haakjes] to
override the usual precedence if you need to.
Data type: a category for values, and every value belongs to exactly one data type.
- Integer (int): indicates values that are whole numbers.
- Floating-point (floats): Numbers with a decimal point, such as 3.14. Note that
even though the value 42 is an integer, the value 42.0 would be a floating-point
number.
- Strings: single quote showing where to begin and end.
'a', 'aa', 'aaa', 'Hello!', '11 cats' '' = blank string
When + is used on two string values, it joins the strings as the string
concatenation operator.
>>> 'Alice' + 'Bob'
'AliceBob'
Combining an + operator on a string and an integer value will result in an error.
Combining an * operator on a string value and one integer value = string
replication operator
>> 'Alice' * 5
'AliceAliceAliceAliceAlice'
‘Alice’ * 5.0 would give an error.
Variable: a box in the computer’s memory where you can store a single value (to use later).
1. Only one word.
2. Use only letters, numbers, and the underscore _ character.
3. Can’t begin with a number.
a) Variable names are (capital letter) case-sensitive.
Assignment statement: consists of a variable name, an equal sign (= assignment
operator), and the value (=integer value) to be stored.
>>> spam = 40
>>> eggs = 2
>>> spam + eggs
42
,A variable is initialized the first time a value is stored in it.
Overwriting the variable: When a variable is assigned a new value, the old value is forgotten.
>>> spam = spam + 2
>>> spam
42
File editor: has some specific features for typing in source code.
- The interactive shell window will always be the one with the >>> prompt.
- The file editor window will not have the >>> prompt.
When there are no more lines of code to execute, the Python program terminates (exits);
that is, it stops running.
# is a comment. Python ignores comments (and the blank lines after it), and you can use
them to write notes or remind yourself what the code is trying to do.
Commenting out: Sometimes, programmers will put a # in front of a line of code to temporarily remove it
while testing a program.
The print() function displays the string value inside the parentheses on the screen.
When Python executes a line, you say that Python 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.
The input()function waits for the user to type some text on the keyboard and
press ENTER. Always returns a string (even if the user typed in a number).
print('It is good to meet you, ' + myName)
The len () function: evaluates to the integer value of the number of characters in that
string.
>>> len('hello')
5
The str() function is handy when you have an integer or float that you want to concatenate to a
string.
>>> str(29)
'29'
>>> print('I am ' + str(29) + ' years old.')
I am 29 years old.
The int() function is helpful if you have a number as a string value that you want to
use in some mathematics. Treat variable as an integer instead of a string:
>>> spam = input()
101
>>> spam = int(spam)
>>> spam *
202.0
The int () function is useful if you need to round a floating-point number down. If you
want to round a floating-point number up, just add 1 to it afterward.
2
, >>> int(7.7)
7
>>> int(7.7) + 1
8
An integer can be equal to a floating point, as they’re both numbers (unlike a string, which is
text).
>>> 42 == 42.0
True
>>> 42.0 == 0042.000
True
/ CH2 /
Flow control statements can decide which Python instructions to execute under which
conditions. There is usually more than one way to go from the start to the end.
Boolean data type has only two values: True and False.
>>> spam = True
>>> spam
True
Comparison operators compare two values and evaluate down to a single Boolean value.
Operator Meaning
== Equal to
!= Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
• The == operator (equal to) asks whether two values are the same as each other.
• The = operator (assignment) puts the value on the right into the variable on the
left.
3
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller chiara-uva. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $7.06. You're not tied to anything after your purchase.