เมธอดและแพ็กเกจ

Python สำหรับผู้ใช้ MATLAB

Justin Kiggins

Product Manager

เมธอดคือฟังก์ชันที่ผูกอยู่กับตัวแปร

  • ใช้งานเฉพาะกับตัวแปรแต่ละประเภท
  • เข้าถึงด้วยจุด (.)
yelling = "WHY ARE YOU YELLING?"
whispering = yelling.lower()
print(whispering)
why are you yelling?
Python สำหรับผู้ใช้ MATLAB

เมธอด .format()

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

print(message)
I have 1765 avocados!
Python สำหรับผู้ใช้ MATLAB

แพ็กเกจของ Python

โลโก้ NumPy

โลโก้ matplotlib

โลโก้ pandas

Python สำหรับผู้ใช้ MATLAB
import math

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

การ import เฉพาะบางส่วนของแพ็กเกจ:

from math import log
log(0.9)
-0.10536051565782628
Python สำหรับผู้ใช้ MATLAB

การตั้งชื่อแทน (alias) ให้แพ็กเกจ

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()
Python สำหรับผู้ใช้ MATLAB

มาลองใช้เมธอดและแพ็กเกจที่มีประโยชน์กัน

Python สำหรับผู้ใช้ MATLAB

Preparing Video For Download...