Life does not come with instructions on how to live, but it does come with trees, sunsets, smiles and laughter, so enjoy your day.

ชีวิตไม่ได้มาพร้อมกับคู่มือการใช้ชีวิต

แต่ชีวิตมาพร้อมกับต้นไม้, พระอาทิตย์ตก, รอยยิ้มและเสียงหัวเราะ 

―Debbie Shapiro

ชนิดของตัวแปรใน Python

ตัวอักษร (Text)str
ตัวเลข (Numberic)intfloatcomplex
Sequence Types:listtuplerange
Mapping Type:dict
เซ็ท (Set)setfrozenset
บูลีน (Boolean)bool
ไบนารี (Binary)bytesbytearraymemoryview

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

my_varieble = type(x)

เช่น

my_variable= str(“Hello World”)
print(my_variable)

👉 Hello World

การกำหนดชนิดตัวแปรของตัวแปรใน Python นั้น ไม่จำเป็นตัองประกาศก็ได้ โดยปกติคอมไพเลอร์จะรู้โดยอัตโนมัติ

x=5                                                 # x เป็นตัวแปรแบบ int
my_text= “Hello World”                              # my_text  เป็นตัวแปรแบบ str
my_array= [“Bangkok”, “Chiang Mai”, “Prachuaup”]    # my_array เป็นข้อมูลแบบ list
Str
  1. ตัวแปร str นั้น  สามารถอยู่ในเครื่องหมาย อัญประกาศ แบบเดี่ยว ('...') หรือ อัญประกาศ แบบคู่ ("...") ก็ได้ ให้ผลเหมือนกัน
  2. อยากจะสั่งพิมพ์คำว่า  don’t หรือคำอื่นๆ ที่มีอัญประกาศ ทำอย่างไร
print("I don\'t know.")     #  ให้ใส่ (\') แทนอัญประกาศในประโยค

👉 I don't know.
หรือ 
print(r"I don't know.")     # ใส่ r ก่อนเครื่องหมายคำพูด ซึ่ง r ในที่นี้มาจาก raw string
👉I don't know.
Don`t copy text!