ในบทช่วยสอนนี้ เราจะเรียนรู้เกี่ยวกับ string.whitespace
สตริง whitespace ถูกกำหนดไว้ล่วงหน้าในโมดูล string ของ Python 3 ประกอบด้วย space, tab, linefeed, return, formfeed, และ vertical tab
ตัวอย่าง
# นำเข้าโมดูล string
import string
# พิมพ์สตริง
print("Hello")
# พิมพ์ whitespace
print(string.whitespace)
# พิมพ์สตริง
print('tutorialspoint')
ผลลัพธ์
การรันโค้ดข้างต้นจะได้ผลลัพธ์ดังนี้
Hello tutorialspoint
หมายเหตุ: การ print(string.whitespace) จะแสดง whitespace characters ซึ่งอาจไม่เห็นชัดบนคอนโซล
สรุป
string.whitespace มี whitespace characters ทั้ง 6 ชนิด หากมีข้อสงสัย กรุณาแจ้งในส่วนความคิดเห็น