my_int = 5
print(my_int)
my_float = 0.3
print(my_float)5
0.3
Lab 02
Romi Hill
September 23, 2026
This will be discussed in person in lab. Here are some helpful commands when we have the discussion:
| Command | What it does | Example |
|---|---|---|
cd |
Changes directory | cd /projectnb/lx394sh/username |
ls |
List contents of directory |
|
pwd |
Print working directory | pwd |
mkdir |
Create a directory in current location | mkdir my_dir_name |
Use conda install PACKAGE in your command line to install Python packages. If you’re on Mac, use the “Terminal”. If you’re on Windows, use the “Anaconda Prompt” (available in Anaconda Navigator”
Open a .ipynb file to answer the following questions! I also suggest leaving comments for your code, either through a Markdown Cell, or in-line comments in Python using #.
intfloatstrlistsetboolNoneFor example:
list with an int?list with an int?str with an int?str with an int?str with an list?For example, what happens when you run the following code?
The take away message here: When you apply an operator to two different data types, the output might not be obvious! This is called implicit type casting. You can read more about this here.
But if you cannot be bothered/not interested, you should still always check what happens when you combine two data types. Or better yet, you can type cast to make explicit what you’re trying to do!
You can also explicitly convert data types.
What do the following operations do?
We can index lists.
We can slice lists.
We can specify the steps
We can reverse lists
We can reverse and specify the number of steps
Recall functions:
What is a function? What are some of the components of a function?
Write a function that outputs the following
I’ll give you the start. Hint: you need to use an operator.
Additional Exercise:
Modify the code so that the default value is “Sophie”. That is, your function should have the following output given these inputs. This should only take 9 characters to type!
True when x and y are anagrams of each other, and false otherwise. Example input and expected output is provided below.Note: You may have noticed : str and -> bool in this sample code. It’s good style to yourself/anyone else using the code that the input parameters should be a str, and the output should be a bool. However, this is not necessary. In fact, Python will still run if the output is not a bool, for example.
Challenge question:
Modify your code so that it also ignores spaces and capitalization. For example:
True when x is a palindrone. Example input and expected output is provided below.