方法与包

面向 MATLAB 用户的 Python

Justin Kiggins

Product Manager

方法是附加在变量上的函数

  • 针对变量类型
  • 用句点访问
yelling = "WHY ARE YOU YELLING?"
whispering = yelling.lower()
print(whispering)
why are you yelling?
面向 MATLAB 用户的 Python

.format() 方法

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

print(message)
I have 1765 avocados!
面向 MATLAB 用户的 Python

Python 包

NumPy 标志

matplotlib 标志

pandas 标志

面向 MATLAB 用户的 Python
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
面向 MATLAB 用户的 Python

包的别名

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_theme()
面向 MATLAB 用户的 Python

来看一些常用方法与包

面向 MATLAB 用户的 Python

Preparing Video For Download...