print() statement:
The print() statement is a very important statement in the language of Python. This command is used to print a variety of things. It can be used in conjunction with lists, strings, integers, tuples and dictionaries (it can also do calculations). It takes three kinds of arguments:
- value(s) to be printed
Eg: >>>print(‘hello. i am learning python’)
hello. i am learning python
Here , ‘hello. I am learning python’ is the argument given.
- separating character or string
This is done by using the sep parameter in Python. The sep statement is used to specify the character or string that separates two or more values inputted into the print() statement.
By default, the separator is an empty space, i.e. ‘ ’.
Eg: >>>print(‘hello’, ‘i am learning python’, sep=‘!’)
hello!i am learning python
- ending character or string
This is done by using the end parameter in Python. The end statement is used to specify the character or string that ends two or more values inputted into the print() statement.
By default the value of the end parameter is \n, i.e. new line.
Eg: >>>print(‘hello’, ‘i am learning python’, sep=‘!’, end=‘!’)
hello!i am learning python!
Pingback: Introduction to Python – Freakgenie