ฟังก์ชันPython str()
ตัวอย่าง
แปลงตัวเลข 3.5 เป็นสตริง:
x =
str(3.5)
ความหมายและการใช้งาน
ฟังก์ชันstr()
แปลงค่าที่ระบุเป็นสตริง
ไวยากรณ์
str(object, encoding=encoding, errors=errors)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
object | Any object. Specifies the object to convert into a string |
encoding | The encoding of the object. Default is UTF-8 |
errors | Specifies what to do if the decoding fails |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
แปลงสตริงเป็นจำนวนเต็ม:
x =
int("12")