Methods and packages

Python for MATLAB Users

Justin Kiggins

Product Manager

Methods are functions attached to variables

  • Specific to the variable type
  • Accessed with a period
yelling = "WHY ARE YOU YELLING?"
whispering = yelling.lower()
print(whispering)
why are you yelling?
Python for MATLAB Users

The .format() method

n_avocados = 1765
message = "I have {} avocados!".format(n_avocados)

print(message)
I have 1765 avocados!
Python for MATLAB Users

Python packages

NumPy Logo

matplotlib logo

pandas logo

Python for MATLAB Users
import math

math.pi
3.141592653589793
math.log(0.9)
-0.10536051565782628

Importing part of a package:

from math import log
log(0.9)
-0.10536051565782628
Python for MATLAB Users

Package aliasing

import datetime as dt

birth_date = dt.datetime(1961,8,4)
# Import NumPy package with common alias import numpy as np x = np.ndarray([1, 2, 3])
# Import pandas package with common alias import pandas as pd df = pd.DataFrame()
# Import Matplotlib pyplot module with common alias import matplotlib.pyplot as plt plt.show()
# Import Seaborn package with common alias import seaborn as sns sns.set()
Python for MATLAB Users

Let's explore some useful methods and packages

Python for MATLAB Users

Preparing Video For Download...