Skip to content

Introduction to Python Sandbox

👋 Welcome to your new workspace! You can use this interactive notebook to take notes, explore the course data, and practice your Python skills. There is also a cheat sheet at the bottom to use as a reference for later!

A sample of the data from Introduction to Python has been defined as lists in the cell below.

Click inside the cell and press "Run" to execute the pre-written code or adapt it and write your own!

# Import numpy
import numpy as np

# Assign the names to a list
names = np.array(['Kiko Calero', 'Armando Benitez', 'Delmon Young', 'Greg Maddux', 'J.D. Drew', 'James Loney', 'Jeff Ridgway', 'Ronny Cedeno', 'Omar Infante', 'Wandy Rodriguez'])

# Assign the positions to a list
positions = np.array(['Pitcher', 'Pitcher', 'Outfielder', 'Pitcher', 'Outfielder', 'Infielder', 'Pitcher', 'Infielder', 'Infielder', 'Pitcher'])

# Assign the heights to a list
heights = np.array([73, 76, 75, 72, 73, 75, 75, 72, 72, 71])

# Print the mean height of the players
print(np.mean(heights))

1 hidden cell

You can click "Add markdown" to add and edit text cells for notes, and "Add Code" to continue practicing your Python code.

Alternatively, you can create a blank Python workspace and code in a fresh notebook!

Introduction to Python Interactive Cheat Sheet

Below are some interactive examples of things you learned from the course. Bookmark this page as a reference and a place to experiment with queries!

Math and variables

You can use Python as a calculator, performing things like addition, subtraction, multiplication, and division.


1 hidden cell

You can assign values to variables using the = sign.


1 hidden cell

You can use the type() function to determine the type of a variable.


1 hidden cell

To convert the type of a variable, you can use functions such as:

  • str() to convert to a string.
  • int() to convert to an integer.
  • float() to convert to a float.

1 hidden cell

Lists

You can create a list using square brackets [], using commas to separate the values.


1 hidden cell

You can slice different parts of a list by using square brackets and numerical indices.

If you want to slice multiple values, you can use : to specify the start and stop (not included) of your slice.

‌
‌
‌