>>> city=input (“Enter Your City: ”) Enter Your City: Madurai >>> print (“I am from “, city) I am from Madurai Example :input( ) without prompt string >>> city=input() Rajarajan >>> print (“I am from”, city) I am from Rajarajan Note that in example- , the input( ) is not having any prompt string, thus the user will not know what is to be typed as input. If the user inputs irrelevant data as given in the above example, then the output will be unexpected. So, to make your program more interactive, provide prompt string with input( ). The input ( ) accepts all data as string but not as numbers.
If a numerical value is entered, the input values should be explicitly converted into numeric data type. The int( ) function is used to convert string data as integer data explicitly. We will learn about more such functions in later chapters. Example : x = int (input(“Enter Number : ”)) y = int (input(“Enter Number : ”)) print (“The sum = ”, x+y) Output: Enter Number : Enter Number : The sum = 12th Computer Chapter - - Python – Variables and Operators Example : Alternate method for the above program x,y=int (input("Enter Number :")),int(input("Enter Number :")) print ("X = ",x," Y = ",y) Output: Enter Number : Enter Number X = Y = .
Comments in Python In Python, comments begin with hash symbol (#) . The lines that begins with # are considered as comments and ignored by the Python interpreter. Comments may be single line or no multi-lines. The multiline comments should be enclosed within a set of ''' ''' (triple quotes) as given below.
# It is Single line Comment ''' It is multiline comment which contains more than one line ''' . Indentation Python uses whitespace such as spaces and tabs to define program blocks whereas other languages like C, C++, java use curly braces { } to indicate blocks of codes for class, functions or body of the loops and block of