DEV Community

jothilingam
jothilingam

Posted on

PRINT function in python

13-07-2024

PRINT() function

print() function is a function that allows us to output to the screen

The print() function has three different uses;

  1. Single quotes (' ')
  2. Double quotes (" ")
  3. Three quotes (“”” “””)-----------for multi line

we can use anyone type quote, cannot use different quote in same line

print()---------------------------#create empty line
Enter fullscreen mode Exit fullscreen mode
print("jothilingam")--------------#string should print with""
Enter fullscreen mode Exit fullscreen mode
print(5)------------------------#number can print without ""
Enter fullscreen mode Exit fullscreen mode
print("jo""jo")--------------print without space
print("jo"+"jo")--------------print without space
answer    jojo
print("jo","jo")--------------print with space
answer     jo jo
Enter fullscreen mode Exit fullscreen mode

print with f-strings

name = "jothi"
print(f"Hello {name}")
# Output : Hello jothi
Enter fullscreen mode Exit fullscreen mode

newline escape character \n

print("jo\nthi")
jo
thi
Enter fullscreen mode Exit fullscreen mode

Parameters of the print() Function:

sepparameter

print("jo","jo",sep="_")...................sep="" is default
answer    jo_jo
Enter fullscreen mode Exit fullscreen mode
print("jo", "lingam", sep='thi')
answer     jothilingam
Enter fullscreen mode Exit fullscreen mode

endparameter

print("jothi",end="lingam")
answer  jothilingam
Enter fullscreen mode Exit fullscreen mode
print("jothi",end="")----------------without space
print("lingam")
answer  jothilingam
Enter fullscreen mode Exit fullscreen mode
print("jothi",end=" ")----------------with space
print("lingam")
answer  jothi lingam
Enter fullscreen mode Exit fullscreen mode

* parameter

print(*"jothilingam")
answer    j o t h i l i n g a m
Enter fullscreen mode Exit fullscreen mode

fileand flushparameters, since these parameters are the parameters that allow us to process the files

Top comments (0)