Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Resumen

Summary notebooks Data Processing

Puntuación
3.0
(2)
Vendido
9
Páginas
20
Subido en
25-03-2023
Escrito en
2022/2023

Summary of the course material for the research skill course Data Processing.

Institución
Grado

Vista previa del contenido

Summary data processing

Week 2
Functions are a block of reusable code. You can ‘call’ the function with the appropriate
parameters.
Creating your own functions:

def function name (parameter list):
statements

Python does not actually run the code inside the function, at least not until the function gets
called.

The keyword ‘return’ is used to communicate information to the program that is outside the
function.
- When you use the command ‘return’ in a function, that ends the processing of the
function. Python will continue with the code that needs to be executed after the call
to the function.
- Every line of code in the function that occurs immediately after a return at the same
level of indentation will always be ignored.
Example:

Def square(a):
Return a*a
Print (“this line will never be printed”)

When calling the function, you will only see a * a
- E.g., square(3)  returns 9
- And it won’t print the line also defined in the function.

The difference between print() and return:
- The print function can only be used for one purpose, the return function however,
can be used wherever we need the executed number, regardless of whether we need
to display it, use it for a calculation, or assign it to a variable.
Example:
Def return3():
Return 3
Print(2 ** return3())
- This returns 8, as you expect it to do.
Or
Def print3():
Print(3)
Print(2 ** print3())
- This will execute the number 3 and also will give you an error.

The print function actually returns the special value None, which cannot be used in a
calculation

,Type casting
 Float()  returns a floating-point value. If the parameter holds an integer, it returns
the same value but with .0. if the parameter holds a float, it returns the same
number. If the parameter holds a string which can be interpreted as an integer/float
it returns the interpretation as a float, otherwise it gives you a runtime error.
 Int()  returns an integer. If the parameter holds an integer, it returns the same
value. If the parameter holds a float, it returns the integer part of a float (float value
rounded down). If the parameter holds a string, and the string contains only digits, it
returns the integer, otherwise it will give a runtime error.
 Str()  has one parameter and returns a string representation.

Calculations
 Abs()  1 numerical parameter. If the value is positive, it will return the value, if it is
negative, it will return the value multiplied by -1.
 Max()  two or more numerical values. Returns the largest
 Min()  two or more numerical values. Returns the smallest
 Pow()  two numerical parameters, returns first to the power of the second.
 Pow(-2, 3)  -8
 Optional third parameter, it will return the value modulo that third parameter.
 Round()  has a numerical parameter and rounds it to a whole number.
 Optional second parameter (which must be an integer). The function will round
the first parameter to the number of decimals specified by the second parameter.
 Len()  one parameter and returns the length of the parameter.

Mathematical functions from the math module
You call the math module by:
Import math
Or
From math import exp, log, etc.
 Exp()  gets one numerical parameter and returns e to the power of that parameter.
 E is a special mathematical value
 Log()  gets one numerical parameter and return natural logarithm of that
parameter.
 Natural logarithm = value which, when e is raised to the power of that value,
gives the requested parameter.
 Log10()  gets one numerical parameter and returns the base-10 logarithm of that
parameter
 Sqrt()  gets one numerical parameter and returns the square root of that
parameter

Random module
 Random()  get no parameters. Returns a random float in the range [0,1)
(1 excluded)
 Randint()  gets to parameters (integers), first smaller than, or equal to, the second.
Returns a random integer in the range of the two parameters.

,  Seed()  initializes the random number generator of Python. If you want a sequence
of random numbers that are always the same for your program, start by calling seed
with a fixed value as parameter, for instance 0.
 If you want to re-initialize the random number generator so that it starts
behaving completely randomly again, call seed()

Boolean values
True and false are Boolean values.
- Datatype = bool
Values that are interpreted as false:
 False
 None
 0
 “ “ (empty string)
 Empty mapping  e.g., empty dictionaries
Every other value is interpreted as True.
The most common Boolean expressions are comparisons

Comparisons
 <
 <=
 ==
 >=
 >
 !=
Common mistake: using a ‘=’ as comparison operator. This is the assignment operator.
- Python produces a runtime error if you try to use a single ‘=’ to make a comparison.

In operator
The in operator is written as ‘in’.
- You can test if a character or a sequence of characters is part of the string using the
in operator.
 opposite of the in operator is the ‘not in’ operator.

Logical operators
 And  placed between two Boolean expressions. The result is True if both
expressions evaluate to true.
 Or  placed between two Boolean expressions The result is True if one of the
expressions evaluates to true. Otherwise, false.
 Not  place in front of a Boolean expression to switch it from true to false or vice
versa.
Be careful with logical operators because combining ‘and’ and ‘or’ might lead to unexpected
results.
- So, instead of writing ‘a and b or c’ you should write  (a and b) or c / a and (b or c)

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
25 de marzo de 2023
Número de páginas
20
Escrito en
2022/2023
Tipo
RESUMEN

Temas

$7.10
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Reseñas de compradores verificados

Se muestran los 2 comentarios
9 meses hace

2 año hace

3.0

2 reseñas

5
0
4
0
3
2
2
0
1
0
Reseñas confiables sobre Stuvia

Todas las reseñas las realizan usuarios reales de Stuvia después de compras verificadas.

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
sophiedekkers54 Tilburg University
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
46
Miembro desde
7 año
Número de seguidores
24
Documentos
3
Última venta
3 meses hace

3.0

2 reseñas

5
0
4
0
3
2
2
0
1
0

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes