Workspace
Victoria Leticia Nogués Brieva/

Introduction to Python

0
Beta
Spinner

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))
# Add your own code here!

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.

# Addition
print(5 + 5)

# Subtraction
print(10 - 5)

# Multiplication
print(5 * 10)

# Division
print(10 / 5)

You can assign values to variables using the = sign.

# Assign a value to x
x = 5

# Print x
print(x)

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

# Assign a variable to x
x = "testing"

# Print the type of x
print(type(x))

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.
# Assign a string variable to y
y = "1"

# Print y as an integer
print(int(y))

# Print y as a float
print(float(y))

Lists

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

# Create a list
my_list = ["Learning", "Python", "is", "fun!"]

# Print the list
print(my_list)

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.




  • AI Chat
  • Code