Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Latest commit

 

History

History
46 lines (46 loc) · 1.34 KB

File metadata and controls

46 lines (46 loc) · 1.34 KB

Print

>>> print(“Hello World”)
Hello World

It can have several parameters.

>>> print(‘Hello’,  12,  ‘98’)
Hello 12 98

The arguments of the print function: sep=’’ Sep is a separator, it is used to divide parameters.

>>> print(‘Hello’, “World’, sep=’-‘)
Hello-World

We can assign an string to the keyword parameter "end". This string will be used for ending the output of the values of a print call. end=’’

>>> print(‘Hello’, ‘World’, end=’!’)
Hello World?

By redefining the keyword parameter "file" we can send the output into a different stream file. file=’’

>>> fh = open("data.txt","w")
>> print("no", file=fh)
>>> fh.close()

Instructions: Put your name and sname to appropriate places, change '*' to parameters of separator '_' and in the end of the line '!'. The print() function can be used with str.format() function

>>> print(“Hello World to {}".format("Geek"))
Hello World to Geek
>>> print(“{} Hello World to {}".format("Hello","Geek"))
Hello World to Geek
>>>a=2
>>> print(“{} is the value of a".format(a))
2 is  value of a

Instructions: put your own name instead of geek and change the value of the variable to something else