πWeek 1 - Lab Intro
Contents
πWeek 1 - Lab Intro#
In this lab introduction we will briefly revisit some of the key topics from lecture 1, focusing on those relevant to lab 1.
Pythonβs Built-in Functions#
Print Function#
print("Drexel Engineering")
Drexel Engineering
You can find more built-in functions
Importing Built-in Modules#
The base package of python contains built-in modules. These have to be imported before they can be used.
You import modules using
import <Module Name>
Random#
We can use random to sample a random integer. This would make a 6-sided die.
import random
dice = random.randint(1,6)
print(dice)
4
You can view everything included in the standard library here
Importing External Packages#
Syntax
Reminder: there are many ways to import packages
from {package name} import {module}
from {package name} import {module} as {name}</code></pre>
Importing Numpy#
A common package for scientific computing is Numpy, it is most commonly imported and given the shortened name np
.
import numpy as np
Use numpy to find the mean of a list of numbers
print(np.mean([1,2,3,4]))
2.5
Variables#
Variables are containers for storing data values.
x = 5
y = "Drexel"
print(x)
5
print(y)
Drexel
Python Operators#
Operators are used to perform operations on variables and values.
For example we can use the +
operator to add two number (or strings together)
5 + 10
15
'Drexel' + ' ' + 'Engineer'
'Drexel Engineer'
Reminder: a few useful operators#
Hereβs a reminder about a few of the operators that may be new to you
Modulus %
#
The remainder after dividing by a number
x = 5
y = 3
print(x % y)
2
Floor Division //
#
The floor division //
rounds the result of division down to the nearest whole number
x = 5
y = 3
print(x // y)
1
Addition and Assignment +=
#
Add to a variable and reassign the value
x = 5
x += 3
print(x)
8
Equal To ==
#
Check to see if two variables are equal
x = 3
y = 5
print(x == x)
print(x == y)
True
False