100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada
logo-home
Python notes $5.96   Añadir al carrito

Otro

Python notes

1 revisar
 150 vistas  4 veces vendidas
  • Grado
  • Institución

Information and Data Management UvA notes on Python.

Vista previa 2 fuera de 7  páginas

  • 28 de febrero de 2022
  • 7
  • 2020/2021
  • Otro
  • Desconocido

1  revisar

review-writer-avatar

Por: beersmadelief • 2 año hace

avatar-seller
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

Los beneficios de comprar resúmenes en Stuvia estan en línea:

Garantiza la calidad de los comentarios

Garantiza la calidad de los comentarios

Compradores de Stuvia evaluaron más de 700.000 resúmenes. Así estas seguro que compras los mejores documentos!

Compra fácil y rápido

Compra fácil y rápido

Puedes pagar rápidamente y en una vez con iDeal, tarjeta de crédito o con tu crédito de Stuvia. Sin tener que hacerte miembro.

Enfócate en lo más importante

Enfócate en lo más importante

Tus compañeros escriben los resúmenes. Por eso tienes la seguridad que tienes un resumen actual y confiable. Así llegas a la conclusión rapidamente!

Preguntas frecuentes

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.

100% de satisfacción garantizada: ¿Cómo funciona?

Nuestra garantía de satisfacción le asegura que siempre encontrará un documento de estudio a tu medida. Tu rellenas un formulario y nuestro equipo de atención al cliente se encarga del resto.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller bastudent. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for $5.96. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

45,681 summaries were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Empieza a vender
$5.96  4x  vendido
  • (1)
  Añadir