Hello World!
Input-Output
Print 'Hello World!'
Accept string as input
input
always returns a string, no matter what input is entered.
Input | word |
---|---|
good |
'good' |
123 |
'123' |
12.3 |
'12.3' |
Accept integer as input
First accept a string as input and convert it into an integer. This conversion is often called type-casting, since we are changing the type of a variable. Here, it goes from str
to int
.
Accept float as input
Similar to the previous how-to.
Print multiple variables
Notice the space that gets added by default between consecutive variables when they are printed. Also note that all get printed on the same line.
Print multiple objects separated by comma
sep
is an parameter of the function print
and stands for separator. The separator is a string that is added between consecutive objects before printing them. The separator defaults to a space, ' '
. In order to separate objects with a comma, sep
has to be set to ','
.
Print multiple objects without separation
year = '22'
term = 'f3'
roll = '001023'
domain = '@ds.study.iitm.ac.in'
print(year, term, roll, domain, sep = '')
22f3001023@ds.study.iitm.ac.in
Note that the argument passed to sep
is the empty string, ''
. This is often called the null string.
Print multiple sentences using a single string
Using triple quotes is a way to store multi-line strings.