Page 295 - AI Ver 1.0 Class 9
P. 295
The print() Function
The print() function is used to print an output on the screen. It converts the expressions into a string before
writing to the screen. Syntax to use the print( ) function is:
print(object(s), sep = separator, end = end)
Where,
• object can be one or more separated by comma and it can be a variable, literal, expression. An object will be
converted to string before printed.
• sep is used as a separator if there are more than one objects.
• end specifies what to print at the end. Default is newline '\n'.
Following are some of the examples of the print( ) function:
Commands Output
print("hello") hello
print("hello", "friends") hello friends
print("hello" + "friends") hellofriends
(This is concatenation of string using "+"
operator)
print("hello", "friends", sep="$") hello$friends
print("hello", "friends", sep="$", end="!") hello$friends!
print("hello", "friends", end="!") hello friends!
print("hello") hello
print() friends
print("friends")
print("hello", end="%") hello%friends
print("friends")
print("hello", "friends", "welcome", sep="#", hello#friends#welcome@
end="@")
print("I am in class", 9) I am in class 9
a = 5
b = 10 Sum of two numbers is 15
print("Sum of two numbers is " + str(a + b))
age = 14 I am 14 years old
print("I am ", age, " years old")
The input() Function
The input( ) function is used to take an input from the user. When, this statement executes then the flow of
the program stops and waits with the cursor blinking for the user to enter a value. The input given by the user
is always a string value in Python.
Introduction to Python 293

