Page 391 - Ai_417_V3.0_C9_Flipbook
P. 391
Commands Output
print("hello", "friends", sep="$", end="!") hello$friends!
print("hello", "friends", end="!") hello friends!
print("hello") hello
print()
print("friends") 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
print("Sum of two numbers is " + str(a + b)) Sum of two numbers is 15
age = 14
print("I am ", age, " years old") I am 14 years old
NOTE: sep and end are always the last two parameters after the objects in the print statements. However both
may have interchange positions.
print(10,20 ,sep="+",end="!")
OR
print(10,20, end="!",sep="+")
Output in both the cases will be same as both the statements are interpreted as same.
The input() Function
The input() function is used to take 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.
The syntax to use the input() function is:
input(prompt)
Where prompt is a string that works as a message for the user at the time of input. For example,
name = input("enter your name: ")
print(name)
When the preceding statement executes, it will ask to enter a name. When you enter the name and press the
Enter key, the entered name will be displayed on the screen:
enter your name: Chirag
Chirag
Let us take another example:
a = input("Enter first number: ") #line 1
Introduction to Python 389

