Lab 2 Notes: Data Types and Variables (Python / JupyterLab)
Lab logistics and expectations
- Lab 2 focuses on data types and variables in Python within JupyterLab.
- Sign-up details: currently there is one presenter today; next lab covers a new topic (lists and dictionaries).
- Presentation format: at the beginning of class, you’ll present a Jupyter notebook and discuss the topic briefly with a classmate.
- Important constraint for Lab 2 next week: the material cannot be a rehash of previous slides; the submission must be original content. The presenter’s material cannot contain obvious code from the lab slides; originality is required regardless of the topic.
- Time expectation: presentations are about five minutes long; come prepared.
- Real-world relevance: data types and variables have clear applications in logic, calculations, and working with usernames and other user-provided data.
JupyterLab basics: how code runs
- JupyterLab notebooks are composed of cells. When you run a cell, Python executes its contents from top to bottom, left to right within the cell, and then moves to the next cell.
- Python acts like a calculator: you can perform simple arithmetic (e.g., 9+10=19) to see immediate results.
- The execution order matters: a later cell can reference variables defined in earlier cells, but if a variable isn’t defined yet, you’ll get an error.
- The system substitutes and prints outputs using the print function (see below for details).
What is a variable? storing data
- A variable is a naming label that stores data for later use in your code.
- You typically assign a value to a variable with an equals sign, e.g.:
name = "Jeff"
- You can retrieve and display the stored value later using the print function:
print(name) # outputs: Jeff
- Variables let you reuse data without retyping it; they are like address labels to the data.
- Python is dynamically typed: you don’t declare a type explicitly; the type is inferred from the value you assign.
Data types covered in the talk
- Integer: a whole number (e.g., 0,1,2,9,10).
- String: a sequence of characters used for text (e.g., a username, names).
- Other common types (referenced conceptually): float (decimal numbers), bool (True/False).
- You can assign different data types to different variables, and you can perform operations appropriate to each type (e.g., arithmetic with numbers, concatenation with strings).
Practical example: combining variables and printing
name = "Jeff"
print(name) # outputs: Jeff
- As you add more code in subsequent cells, you can reuse this variable or update it with a new value:
name = "Alex"
print(name) # outputs: Alex
- The print function can output any data type (string, int, float, etc.).
Variable naming: rules and best practices
- You can create as many variables as you want, but pay attention to naming rules:
- You cannot start a variable name with a number (e.g., 1name is invalid).
- You can include letters, digits after the first character, and underscores (e.g., name1, firstname).
- Spaces are not allowed in variable names (use underscores to separate words).
- Descriptive names are best (e.g., username$, not something vague).
- Mixing numbers only in the middle or end of a name is fine; avoid starting with numbers.
Strings: manipulation and methods
- Strings can be processed with methods that alter their content (examples mentioned in the talk):
- strip(): removes leading/trailing whitespace
- upper(): converts to uppercase
- lower(): converts to lowercase
- Example workflow:
text = " Hello World "
text_stripped = text.strip() # "Hello World"
text_upper = text_stripped.upper() # "HELLO WORLD"
text_lower = text_stripped.lower() # "hello world"
- In the talk, there was a note about applying case changes after stripping whitespace before using the string further (e.g., when preparing strings for display or comparison).
- There may also be a mention of length-related syntax (e.g., obtaining the length of a string), which has its own syntax different from simple methods above.
More concrete notes on strings vs. other types
- Strings are a common data type for names, usernames, and textual data; integers are used for counting and arithmetic.
- The slide material indicates that some string-specific operations (like strip, upper, lower) have distinct syntax and should be learned early, since they do not apply to numeric types.
- Be mindful that some operations (like len()) are primarily defined for sequences (strings, lists, tuples) and do not apply to plain integers.
Working with folders, paths, and notes from slides (conceptual example)
- The talk includes a practical, if informal, example of creating a folder (e.g., a project folder) and organizing notes within JupyterLab.
- The point is to illustrate how strings can be used to name or label folder structures or files, reinforcing the link between variables, strings and real-world tasks.
Lab 2 presentation constraints and workflow
- Each presenter must prepare an original notebook; content should not be a direct rehash of previous slides.
- The topic can be anything related to Python, but the material must be original and not copied from slides.
- The presenter will discuss the topic for about five minutes in class.
- Collaboration: you’ll work with a classmate to present a brief overview of the topic.
- The instructor will grade on understanding of the material, the ability to explain concepts clearly, and the originality of the notebook.
Connections to broader course concepts
- Data types and variables are foundational to any programming task; they underpin most computational logic, calculations, and user-facing features (like usernames).
- The material connects to prior lectures about how computers store data and how programs manipulate data types.
- This lab provides a practical bridge between theory (data types, typing discipline) and practice (writing, organizing, and presenting code).
Ethical, philosophical, and practical implications
- Avoiding copying slides reinforces academic integrity and encourages genuine understanding.
- Clear naming and code readability are ethical practices that improve collaboration and long-term maintenance.
- The emphasis on original work aligns with practical software development principles: readable code, well-documented logic, and reusable components.
Quick reference: key takeaways
- A variable stores data for later use; you assign with
name = value and retrieve with print(name). - Variable names must not start with a digit; use underscores to separate words and keep names descriptive.
- Python is dynamically typed; the data type is inferred from the assigned value.
- Strings have useful methods such as
strip(), upper(), and lower() to preprocess text before use. - Arithmetic is straightforward in Python (e.g., 9 + 10 = 19$$).
- Lab 2 requires originality in content; you will present a notebook with a five-minute talk and discuss the topic with a partner.
- Homework references and further guidance are provided on the back or end of the slides; follow the citation guide.
Homework and slides guidance (from lecture)
- The homework location is described as being on the back of the slides; be sure to locate the relevant section (e.g., topics like floats were mentioned in passing).
- If you have questions, refer to the instructor or slides, and use the citation guidance provided in the lecture materials.