- Lab
- Core Tech

Python Data Essentials: Python Introduction Hands-on Practice
In this lab, you'll dive into Python basics using Jupyter Notebooks. You'll create and print Python identifiers, Boolean, string, and numeric literals, and apply arithmetic, comparison, and logical operators. The lab also introduces Python packages, focusing on the 'pprint' module for better data structure visualization. You'll build and explore lists, tuples, and sets, gaining practical skills in Python's foundational elements and data handling, essential for advanced programming tasks.

Path Info
Table of Contents
-
Challenge
Understanding Python Identifiers, Literals, and Operators
Jupyter Guide
We've got jupyter setup in a sanbox environment all ready for you to practice some of the concepts you've been learning. To get started, open the file on the right entitled "Step 1...". You'll complete each task for Step 1 in that Jupyter Notebook file. Remember, you must run the cells
(Ctrl/Cmd(β) + Enter)
for each task before moving onto the next task in the Jupyter Notebook. Continue until you have completed all tasks in this step. Then when you are ready to move onto the next step, you'll come back and click on the file for the next step until you have completed all tasks in all steps of the lab.
Understanding Python Identifiers, Literals, and Operators
To review the concepts covered in this step, please refer to the Basics of Python module of the Python Data Essentials: Python Introduction course.
Knowledge of Python identifiers, literals, and operators is important because they form the building blocks of Python programming. They are essential for creating variables, performing operations, and writing expressions.
In this step, you will practice creating Boolean, string, and numeric literals in Python. You will also learn about Python identifiers and how to use them. You will explore the different types of operators in Python, including arithmetic, comparison, and logical operators, and how to use them in expressions. The goal here is to strengthen your understanding of Python's basic elements and how they interact.
Task 1.1: Creating Python Identifiers
Create a Python identifier by assigning the value
5
to a variable. Print the value of the variable.π Hint
Use the assignment operator
=
to assign a value to a variable. Use theprint(variable_here)
function to print the value of the variable.π Solution
my_identifier = 5 print(my_identifier)
Task 1.2: Creating Boolean Literals
Create two Boolean literals, one representing
True
and the other representingFalse
. Print the values of the literals.π Hint
Use the keywords
True
andFalse
to create Boolean literals. Use theprint()
function to print the values of the literals.π Solution
my_true_literal = True my_false_literal = False print(my_true_literal) print(my_false_literal)
Task 1.3: Creating String Literals
Create a string literal and print its value.
π Hint
Use single or double quotes to create a string literal. Use the
print()
function to print the value of the literal.π Solution
my_string_literal = 'Hello, Python!' print(my_string_literal)
Task 1.4: Creating Numeric Literals
Create a numeric literal and print its value.
π Hint
You can create a numeric literal by simply writing a number. Use the
print()
function to print the value of the literal.π Solution
my_numeric_literal = 42 print(my_numeric_literal)
Task 1.5: Using Arithmetic Operators
Perform an arithmetic operation using Python's arithmetic operators and print the result.
π Hint
You can use operators like
+
,-
,*
,/
,//
,%
, and**
to perform arithmetic operations. Use theprint()
function to print the result.π Solution
result = 10 * 5 print(result)
Task 1.6: Using Comparison Operators
Perform a comparison operation using Python's comparison operators and print the result.
π Hint
You can use operators like
==
,!=
,<
,>
,<=
, and>=
to perform comparison operations. Use theprint()
function to print the result.π Solution
result = 10 > 5 print(result)
Task 1.7: Using Logical Operators
Perform a logical operation using Python's logical operators and print the result.
π Hint
You can use operators like
and
,or
, andnot
to perform logical operations. Use theprint()
function to print the result.π Solution
result = True and False print(result)
-
Challenge
Working with Python Packages and Data Structures
Working with Python Packages and Data Structures
To review the concepts covered in this step, please refer to the Python Packages and Data Structures module of the Python Data Essentials: Python Introduction course.
Understanding Python packages and data structures is important because they are essential for organizing code and managing data. Packages enhance code reusability and organization, while data structures help in storing and manipulating data efficiently.
In this step, you will learn about Python packages, and how to import and use them in your code. We'll be using the pprint module which has been pre-installed for you. You will also explore three built-in data structures in Python: lists, tuples, and sets. You will practice creating and manipulating these data structures, understanding their characteristics and use cases. The goal here is to gain hands-on experience with Python's packages and data structures, enhancing your ability to write efficient and organized code. (Instruct the user in the descriptions to print thre results)
Task 2.1: Importing the pprint module
Import the pprint module from Python's standard library. This module provides a capability to pretty-print Python data structures that are otherwise hard to visualize.
π Hint
Use the
import
keyword followed by the name of the module, which ispprint
in this case.π Solution
import pprint
Task 2.2: Understanding the usefulness of pprint
To understand why
pprint
is useful, use the provided code to create a complex data structure. Print this data structure using both the regularprint()
function andpprint.pprint()
. Compare the outputs to see the difference in readability.π Hint
Use the provided code to make a complex data structure and print it using both
print(data)
andpprint.pprint(data)
.π Solution
# Provided code for complex data complex_data = [ {"A", "Set", "Here"}, ("This", "is", "a", "tuple", "with", 7, "elements"), [True, False], "A somewhat lengthy string", 0, 3.141529, ] # Print complex data normally and with pprint print("---Complex Data with Pretty Print---") pprint.pprint(complex_data) print("---Complex Data with Normal Print---") print(complex_data)
Task 2.3: Creating a list
Create a list named
my_list
with the following elements: 1, 2, 3, 4, 5. Then, print the list using the pprint function.π Hint
Use square brackets
[]
to create a list. To print the list, usepprint.pprint(my_list)
.π Solution
my_list = [1, 2, 3, 4, 5] pprint.pprint(my_list)
Task 2.4: Creating a tuple
Create a tuple named
my_tuple
with the following elements: 'a', 'b', 'c', 'd', 'e'. Then, print the tuple using the pprint function.π Hint
Use parentheses
()
to create a tuple. To print the tuple, usepprint.pprint(my_tuple)
.π Solution
my_tuple = ('a', 'b', 'c', 'd', 'e') pprint.pprint(my_tuple)
Task 2.5: Creating a set
Create a set named
my_set
with the following elements: 'apple', 'banana', 'cherry'. Then, print the set using the pprint function.π Hint
Use curly braces
{}
to create a set. To print the set, usepprint.pprint(my_set)
.π Solution
my_set = {'apple', 'banana', 'cherry'} pprint.pprint(my_set)
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the authorβs guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.