Latest web development tutorials

expandtabs Python3 () วิธีการ

สตริง Python3 สตริง Python3


ลักษณะ

expandtabs () วิธีการสัญลักษณ์แท็บสตริง ( '\ t') เข้าไปในพื้นที่แท็บสัญลักษณ์ ( '\ t') เป็นจำนวนเริ่มต้นของช่องว่างที่ 8

ไวยากรณ์

expandtabs () วิธีไวยากรณ์:

str.expandtabs(tabsize=8)

พารามิเตอร์

  • tabsize - ระบุสัญลักษณ์แท็บสตริงแปลง ( '\ t') ลงอักขระช่องว่าง

ราคาย้อนกลับ

วิธีการสร้างสตริงใหม่ผลตอบแทนที่เป็นสัญลักษณ์แท็บสตริง ( '\ t') ลงในช่องว่างหลัง

ตัวอย่าง

ตัวอย่างต่อไปนี้แสดงให้เห็นตัวอย่างของ expandtabs () วิธีการ:

#!/usr/bin/python3

str = "this is\tstring example....wow!!!"

print ("原始字符串: " + str)
print ("替换 \\t 符号: " +  str.expandtabs())
print ("使用16个空格替换 \\t 符号: " +  str.expandtabs(16))

ตัวอย่างของผลการส่งออกดังกล่าวข้างต้นมีดังนี้

原始字符串: this is     string example....wow!!!
替换 \t 符号: this is string example....wow!!!
使用16个空格替换 \t 符号: this is         string example....wow!!!

สตริง Python3 สตริง Python3