ความหมายที่แท้จริงของ string ในภาษาไพธอน นั้น อธิบายว่า " สตริง คือ ลำดับของตัวอักษรที่ถูกห่อหุ้มไว้ด้วยเครื่องหมาย single quote('...') หรือ double quote ("...") "
"How do you do?"
'My name is Mr.P'
"สวัสดี ประเทศไทย"
ไพธอนมีความสามารถในการนำสตริงมาต่อกัน ด้วยการนำสตริงแต่ละมาวางต่อกัน โดยเว้นช่องว่างไว้
a = "My name" ' is ' ' wisit '
print a
>>>
My name is wisit
msg = 'Python is a general-purpose high-level \
programming language.Its design philosophy \
emphasizes code readability '
print msg
>>>
Python is a general-purpose high-level programming language.Its design philosophy emphasizes code readability
msg = """
Python supports multiple programming paradigms
(primarily object oriented, imperative, and functional)
and features a fully dynamic type system
and automatic memory management, similar to that of Perl,
Ruby, Scheme, and Tcl. Like other dynamic languages,
Python is often used as a scripting language".
"""
print msg
>>>
Python supports multiple programming paradigms
(primarily object oriented, imperative, and functional)
and features a fully dynamic type system
and automatic memory management, similar to that of Perl,
Ruby, Scheme, and Tcl. Like other dynamic languages,
Python is often used as a scripting language".
print len(msg)
>>>
304
ในที่นี้เราต้องการให้แสดงประโยค ที่มีเครื่องหมายคำพูด " " (double quote) รวมอยู่ด้วย
print "\" You will never walk alone \""
>>>
" You will never walk alone "
นอกจากนี้ ยังมีรหัส Escape Sequence อีก ดูได้จากตาราง
ตารางรหัส Escape Sequence
print '\x50\x79\x74\x68\x6f\x6e'
>>>
Python
|

