Posted in Home

Input/Output

Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard.

  • input ( type your input here)
  • raw_input ( type your input here )

input ( ) : This function first takes the input from the user and then evaluates the expression, which means Python automatically identifies whether user entered a string or a number or list. If the input provided is not correct then either syntax error or exception is raised by python. For example:

  • Các nhà phát triển thường có nhu cầu tương tác với người dùng, để lấy dữ liệu hoặc cung cấp một số loại kết quả. Hầu hết các chương trình ngày nay đều sử dụng hộp thoại như một cách để yêu cầu người dùng cung cấp một số kiểu đầu vào.
  • Trong khi Python cung cấp cho chúng ta hai hàm có sẵn để đọc đầu vào từ bàn phím.
    • input (lời nhắc)
    • raw_input (lời nhắc) input ():
  • Hàm này trước tiên lấy đầu vào từ người dùng và sau đó đánh giá biểu thức, có nghĩa là Python tự động xác định xem người dùng đã nhập một chuỗi hay một số hoặc danh sách. Nếu đầu vào được cung cấp không chính xác thì một trong hai lỗi cú pháp hoặc ngoại lệ được đưa ra bởi python. Ví dụ :
Python program showing
 a use of input()
 val = input("Enter your value: ") 
 print(val) 
Advertisement

Author:

My name is Truong Thanh, graduated Master of Information Technology and Artificial Intelligent in Frankfurt University,Germany. I create this Blog to share my experience about life, study, travel...with friend who have the same hobbies.

2 thoughts on “Input/Output

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s