อินพุตผู้ใช้ Python
ข้อมูลผู้ใช้
Python อนุญาตให้ผู้ใช้ป้อนข้อมูล
นั่นหมายความว่าเราสามารถขอให้ผู้ใช้ป้อนข้อมูลได้
วิธีการนี้แตกต่างกันเล็กน้อยใน Python 3.6 กับ Python 2.7
Python 3.6 ใช้input()
วิธีการ
Python 2.7 ใช้raw_input()
วิธีการ
ตัวอย่างต่อไปนี้จะถามถึงชื่อผู้ใช้ และเมื่อคุณป้อนชื่อผู้ใช้ ชื่อผู้ใช้จะถูกพิมพ์บนหน้าจอ:
Python 3.6
username = input("Enter username:")
print("Username is: " + username)
Python 2.7
username = raw_input("Enter username:")
print("Username
is: " + username)
Python หยุดทำงานเมื่อกล่าวถึงinput()
ฟังก์ชัน และดำเนินการต่อเมื่อผู้ใช้ป้อนข้อมูลบางอย่าง