Get startedGet started for free

Python modularity in the wild

In the slides, we covered 3 ways that you can write modular code with Python: packages, classes, and methods. For reference, you can see the example code we reviewed below.

# Import the pandas PACKAGE
import pandas as pd

# Create some example data
data = {'x': [1, 2, 3, 4], 
        'y': [20.1, 62.5, 34.8, 42.7]}

# Create a dataframe CLASS object
df = pd.DataFrame(data)

# Use the plot METHOD
df.plot('x', 'y')

In this exercise, you'll utilize a class & a method from the popular package numpy.

This exercise is part of the course

Software Engineering Principles in Python

View Course

Exercise instructions

  • Complete the import statement to load the numpy package.
  • Use numpy's array class to define arr.
  • Use arr's sort method to sort the numpy array.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# import the numpy package
import ____ as np

# create an array class object
arr = np.____([8, 6, 7, 5, 3, 0, 9])

# use the sort method
arr.____()

# print the sorted array
print(arr)
Edit and Run Code