Thursday, August 9, 2018

Print Function in Python Programming language


Among many other functions, 'print ()' function is used in Python Programming language to display values. To concatenate both variables and string, Python uses '+' operator like:
str1="I am "
str2="Indian"
str3=str1 + str2
print(str3) # Output would be 'I am Indian'

Again another example on integer values

x=5
y=10
print(x+y) """ Output would be 15 - numeric addition would be performed first and then print () would display"""

But the following statement will signal error

str1="Age of Suddhashil is:"
x=14
print(str1 + x)

Numeric values and string values can not be used.

'n' is known as new line character in Python and different type values can be separated within print () using comma (,).

x=14
print("Age of Suddhashil is \n", x)

The output will be:
Age of Suddhashil is
14

We can use double quotes or single quotes to denote string but one point to be remembered that they should be used together.

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner