Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีใช้เครื่องหมายคำพูดคู่ (Double Quotation) ใน Python

สัญลักษณ์เครื่องหมายคำพูด ใช้สร้างออบเจ็กต์สตริง (string object) ใน Python Python รู้จัก single quotes, double quotes และ triple quoted strings ลิทเทอรัลสตริงเขียนได้โดยการล้อมรอบลำดับตัวอักษรด้วย single quotes ('hello') หรือ double quotes ("hello")

>> var1 = 'hello'
>>> var1
'hello'
>>> var2 = "hello"
>>> var2
'hello'

หากต้องการฝังข้อความที่มี single quotes ภายใน สตริงควรเขียนใน double quotes

>> var = "Welcome to 'Python Tutorial' from TutorialsPoint"
>>> var
"Welcome to 'Python Tutorial' from TutorialsPoint"