Most of the Scripts deal with
Keyboard Input. Though other forms of Input comes from Database or other
Scripts but in most cases the input comes from KeyBoard.
There will be interactive
scripts that need manual intervention by entering certain data.
The input of the user will be interpreted. If the user e.g. puts in an integer value, the input function returns this integer value. If the user on the other hand inputs a list, the function will return a list.
Input - The Most basic function
used for Entering data as input from keyboard is by using the input function as
>>> name =
input("What is Your Name - ")
What is Your Name -
"jagadish"
>>> print
name,type(name)
jagadish <type 'str'>
>>> age =
input("Enter age ?")
Enter age ?2
>>> print
age,type(age)
2 <type 'int'>
One important feature of the
input function is that it takes the input and cast that to the correct Data
Type.
Raw_input – There is one more
function called raw_input which will not cast the value entered.
>>> age =
raw_input("Your age? ")
Your age? 23
>>> print
age,type(age)
23 <type 'str'>
>>>
programming_language = raw_input("Your favourite programming languages?
")
Your favourite programming
languages? ["java","c","c++"]
>>> print
programming_language,type(programming_language)
["java","c","c++"]
<type 'str'>
Whatever the value entered
,Python takes them as String.
No comments :
Post a Comment