ตัวแปร

Python เบื้องต้นสำหรับการเงิน

Adina Howe

Professor

การกำหนดตัวแปร

เก็บข้อมูลที่สามารถอ้างอิงได้ในโค้ด

  • ตัวอย่าง: msft_stock, interest_rate, bonds
  • ชื่อ = ค่า: interest_rate = 0.05

 

ชื่อตัวแปร

  • ใช้ตัวอักษรพิมพ์ใหญ่หรือพิมพ์เล็ก ตัวเลข และขีดล่างได้
  • ห้ามขึ้นต้นด้วยตัวเลข
  • ชื่อบางชื่อเป็นคำสงวนใน Python (เช่น class หรือ type) ควรหลีกเลี่ยง
Python เบื้องต้นสำหรับการเงิน

การกำหนดตัวแปรใน Python

# Correct
day_2 = 5   

# Incorrect, variable name starts with a digit
2_day = 5   
Python เบื้องต้นสำหรับการเงิน

ใช้ตัวแปรวิเคราะห์แนวโน้มหุ้น

$$ \text{Price to earning ratio} = \frac{\text{Market price}}{\text{Earnings per share}} $$

price = 200
earnings = 5

pe_ratio = price / earnings
print(pe_ratio)
40
Python เบื้องต้นสำหรับการเงิน

มาฝึกกันเถอะ!

Python เบื้องต้นสำหรับการเงิน

Preparing Video For Download...