Python Guide | Using Keyboard Input Function. (input & raw_input).
Python Keyboard Input. Here is a basic python tutorial, we will learn how to use input keyboard function on this program. Almost every program certainly use the keyboard input commands. In fact there are a various of ways to sent an input. For example input from keyboard, from mouse click, input from database, input from another computer. For this case, we will show you how to use input function, we can input string data or integer data.
There are two kinds of input commands you need to know,
- First, raw_input
- This command reads a line from input, then returns a string by stripping a trailing newline.
- Second, input
- Used to get expression from the keyboard input, for example mathematics expression (3*3, 9+2, 5/2, ...etc)
So, if you still confuse with my explanations. Now follow the tutorial guide below.
Raw_input
- Syntax 1.
- Syntax 2. the syntax read the Address using raw_input() and display back on the screen using print():
- Syntax 3.
data = raw_input('please input your data here :')
print (data)
name=raw_input('Who is your name ? ')
print ("Hello %s, Nice to meet you" % name);
name=raw_input("Who is your name\t:");
Address=raw_input("Where is your Address\t:");
print"Your Name is\t\t:",name
print"You live in\t\t:",Address
Input.
Only Integer data type can be entered here.
- Math Operations.
- the syntax read the Address using raw_input() and input () then display back on the screen using print():
result=input("Calculation :")
print result
yourname = raw_input("What's your name? ")
print("Nice to meet you " + yourname + "!")
age = input("Your age? ")
print("So, you are already " + str(age) + " years old, " + yourname + "!")
0 comments:
Post a Comment