100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

Python notes

Rating
4.0
(1)
Sold
4
Pages
7
Uploaded on
28-02-2022
Written in
2020/2021

Information and Data Management UvA notes on Python.

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
February 28, 2022
Number of pages
7
Written in
2020/2021
Type
Other
Person
Unknown

Subjects

Content preview

PYTHON

WEEK 1

Variables
- String: text, images, messages
- Integer: number without decimals
- Float: number with decimals
- print(type(variable)) in order to determine the type of the variable.

Variable type conversion
- Cannot add two different types of variables (e.g. one cannot add string and integer/float), so therefore conversion is necessary.
- Convert to:
o String (str(variable))
o Integer (int(variable))
o Float (float(variable))

Rules
- Separate by a comma (,)

Inputs
- input: requires user to fill data
- Asking the user to type a value, reading from a file, reading a network connection, accessing a database.
- Store the result in a variable. The variable type will be a string. One may need to convert the variable into an integer or a float.

Operations
- Standard operators in order of priority:
o Power (**)
o Multiply (*)
o Divide (/)
o Plus (+)
o Minus (–)
- Parentheses are used to show priority.

Output
- What is presented to the user.
- print: displays text.
- Integers and floats do not use quotation marks, whereas strings do.

Rounding numbers
- round (variable, decimal spaces)

WEEK 2

Conditions
- Doing different things depending on different values.
- If… then…, else….
- if condition:
print
- else:
print
print(“Ending statement”)
- Indentations: the spaces before print are mandatory.
- A condition is a calculation that has a Boolean result: it is either true or false.
o print(comparison)
o It will print either “true” or “false”
- Comparisons:
o < less than
o <= less than or equal
o > higher than
o >= higher than or equal
o == equal
o != not equal, indifferent

Multiple conditions
- When a and b are conditions:
o a and b: TRUE when both conditions are TRUE
o a or b: TRUE when any condition is TRUE.

, Control flow
- What instructions will be executed?
o Instructions run in sequence, line by line.
o In case of error, the code after the error is not executed,
o The code can be divided in blocks of code, blocks are indicated by the indentation.
 Lines at the same indentation level belong to the same block.
 Indentations should only happen when there is a need for a separate block: after if, for, while, defining a function, or a class. It
should not happen in the middle of a block, or it generates and issue.

Lists
- A list is a variable that contains not just one value, but multiple values.
- Values are called elements.
- Each element is stored at an index.
- Indexes start at 0.
- The number of elements is called length of the list.
- Create lists using [ ].
- Separate elements with (,).
- Do not call a variable “list”. It is a function name.
- Counting the number of elements in a list:
o len(the_list)
- Access:
o The first item has an index of 0.
o For convenience, the last item has an index of -1.
o If there are 5 items, the index goes from 0-4.
o Accessing element at index i (the_list [i]).
- Modification:
o Modification of the value of the element at index i.
o the_list[i] = new_value
- Concatenation:
o Putting two lists together.
o the_list1 + the_list2
o One can also add a list that contains only one string.
- Check if a value is in a list:
o The result is true or false.
o if value (not) in the_list:
print
Strings
- A list of characters, except no modification is possible.

For loops
- Print each letter in variable
for x in variable:
print (x)
- Print each item of list
for x in list:
print (x)
- Print a word multiple time
for x in list:
print (“Word”)
- Sum:
o Start with a total at 0.
o For each value in the list, add it to the total.
o for value in the_list.
o Example:
my_list = [1, 2, 3]
total = 0
for elt in my_list:
total = total + elt
print(total) if you want the total at the end of each element in the list
print(total) if you want the total at the end

Range
- Print numbers in a particular range
- for x in range(number):
print

Reviews from verified buyers

Showing all reviews
3 year ago

4.0

1 reviews

5
0
4
1
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
bastudent Universiteit van Amsterdam
Follow You need to be logged in order to follow users or courses
Sold
60
Member since
5 year
Number of followers
51
Documents
0
Last sold
1 month ago

3.4

8 reviews

5
3
4
1
3
2
2
0
1
2

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions