Page 112 - Computer - 6
P. 112
Try This
Logical Thinking
Tick ( ) the correct and Cross ( ) out the incorrect variable names in Python from the given variable names:
Report&1 MyName123 3Address Your Name
Report_ABC ABCD1 document _AGE
Assigning Values to Variables
Every variable must have a value. The value stored in a variable is processed during the program’s
execution. The Assignment operator ‘ = ’ (equal to) is used to assign a value to a variable.
For example, to assign the value 10 to variable Age, the command is: Age = 10
Mind Fog ERROR
Remember to enclose text values within ‘ ’ or “ ” while assigning them to a variable. The ‘ ’ or “ ” tells Python
that the value is to be considered as text and no mathematical operations are allowed on it.
INPUT AND OUTPUT OPERATIONS IN PYTHON
Python provides two in-built functions for performing input and output operations. Input operations
involve accepting data values from the user and storing them in a variable. Output operations involve
displaying messages or values of variables and expressions on the screen. Let us learn about the output
and input operations.
print( ) Function
The print( ) function is used to display the value of a variable, an expression, or text messages on the
screen. The syntax of the print( ) function is:
print(text message/variable name/expression)
The print( ) function can display multiple values also. Commas (,) are used to separate the different
values. The following examples illustrate the use of the print( ) function.
input( ) Function
The input( ) function is used to accept data from the user and store it in a variable. The syntax for the
input( ) command is:
<variable name> = input(“Message to display”)
The input function always treats every input as text or string data.
Let us create a program to understand the use of variables, input( ), and output( ) functions.
110