INPUT FROM USER AND STORE IT IN VARIABLE
We have discussed in the earlier videos and blogs regarding variables and multiple assignments. Now let’s move on with
taking real time inputs from user and storing it in a variable.
Name = input(“Enter the Name : ”)
This function is used to ask real
time data from users and store it in the variable defined as Name. This
function takes the value in string. This means when you give input as a numeric
value, it also considers it as a string input and you can access it as I have
explained in the video. To consider this string as numeric value or integer, we
need to type cast the taken input as shown.
Age = int(input(“Enter your age
:”))
This function will type cast your
string into an integer value.
Type Casting: In simple words,
it means conversion of data type. To make use of programming approach in day to
day life, conversion of data type is very useful. As explained earlier input()
function considers the value in string but if we need to convert it into an
integer type casting is required.
Comments
Post a Comment