Làm thế nào để bạn kiểm soát đầu vào trong python?
❮ Chức năng tích hợp sẵn Thí dụHỏi tên người dùng và in nó print('Nhập tên của bạn. ') Định nghĩa và cách sử dụngHàm Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google9 cho phép người dùng nhập liệu cú phápGiá trị tham sốParameterDescriptionpromptA Chuỗi, đại diện cho một thông báo mặc định trước đầu vàoThêm ví dụThí dụSử dụng tham số nhắc để viết tin nhắn trước khi nhập x = input('Nhập tên của bạn. ') ❮ Chức năng tích hợp sẵn Ví dụ sau yêu cầu tên người dùng và khi bạn nhập tên người dùng, nó sẽ được in trên màn hình Trăn 3. 6tên người dùng = input("Nhập tên người dùng. ") Trăn 2. 7tên người dùng = raw_input("Nhập tên người dùng. ") Python ngừng thực thi khi nói đến hàm Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google9 và tiếp tục khi người dùng nhập một số thông tinHãy xem cách sử dụng Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google11, Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google12 và Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google13 để chứng minh đầu ra văn bản trên màn hình và bảng điều khiển input (): This function first takes the input from the user and converts it into a string. The type of the returned object always will be cú pháp inp = input('STATEMENT') Example: 1. >>> name = input('What is your name?\n') # \n ---> newline ---> It causes a line break >>> What is your name? Ram >>> print(name) Ram # ---> comment in python Python3Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google1 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google2 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google3 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google4 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google5 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google6 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google7 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google8 What is your name? Ram Ram0 What is your name? Ram Ram1 What is your name? Ram Ram2 đầu ra Lấy Chuỗi làm đầu vào Python3What is your name? Ram Ram3 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google5 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google6 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google7 What is your name? Ram Ram7 What is your name? Ram Ram8 What is your name? Ram Ram9 What is your name? Ram Ram1____211 đầu ra What is your name? Ram Ram Cách hoạt động của hàm nhập liệu trong Python.
Mã số. Python3Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google12 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google13 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google3 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google15 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google5 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google6 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google7 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google19 What is your name? Ram Ram0 What is your name? Ram Ram1____222 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google23 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google5 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google6 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google7 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google27 What is your name? Ram Ram0 _______41____230 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google3 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google32 What is your name? Ram Ram1 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google7 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google35____236 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google37 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google38 What is your name? Ram Ram1 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google7 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google41 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google36 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google37 Enter Employee Name: Jessa Enter salary: 8000 Enter Company name: Google Printing Employee Details Name Salary Company Jessa 8000 Google44 đầu ra. raw_input(). Chức năng này hoạt động trong phiên bản cũ hơn (như Python 2. x). Hàm này lấy chính xác những gì được nhập từ bàn phím, chuyển đổi nó thành chuỗi, sau đó trả về biến mà chúng ta muốn lưu trữ |