Print() Function in Python

In blog.codersty.com we will handle Python Tutorials and print (), an important function in Python. What sounds like I hear the function for now, do not confuse the subject of the function in more detail in the future I will handle the function you need to know what this function is and how to use it is sufficient for the moment you can reach here if you look at the What Is Python Data Types ?. Come on then, pleasant readings 🙂.

 

What is the Python Print() Function

To put it briefly, printf () is a function that allows us to print keywords the screen.

 

How to Use the Python Print() Function

The Print () function is available in three different uses

  • Single quotation (‘‘)
  • Double quotes (” “)
  • Three quotes (“” ”“ ””)

Let us illustrate with an example;

print('blog.codersty.com Python Tutorials')
print("blog.codersty.com Python Tutorials")
print("""blog.codersty.com Python Tutorials""")

and you get the same result in all three uses, so why do you have three different ways of using it ? Let me tell you about it with a few examples. If you write an example like this;

print('Ali's lesson ended early today.')

you will probably encounter an error like this;

 

File “C: /Users/Gokmen/Desktop/pythontutorial/app.py”, line 1
print (‘Ali’s lesson ended early today’) ^ SyntaxError: invalid syntax

 

The reason for syntax error is that Python starts with the first quotation mark it sees and ends with the second quotation mark, and ends with the syntax error because it cannot read the text after the second quotation mark. For such a use would be more accurate. Therefore, using two quotes or three quotes will prevent you from getting this kind of error.

 

Python Print() Parameters of the Function

Don’t worry if you have a parameter. I will explain the parameters in detail about the function.

 

1. Python Print end Parameter

At the end of the values that we give to the screen with this parameter print () function, we specify which operation to do with an example; Let’s write two print () functions in a row;

print('blog.codersty.com Python Tutorials')
print('blog.codersty.com Python Tutorials')

and we will get an output like this;

blog.codersty.com Python Tutorials
blog.codersty.com Python Tutorials

So how can we print these two print () functions side by side;

print('blog.codersty.com Python Tutorials',end='') 
print('blog.codersty.com Python Tutorials')

The output is as follows;

blog.codersty.com Python Tutorialsblog.codersty.com Python Tutorials

as you can see, it combined the two outputs because we didn’t specify it in the end parameter, so let’s print with commas;

print('blog.codersty.com Python Tutorials',end=',') 
print('blog.codersty.com Python Tutorials')

our output will be like this:

blog.codersty.com Python Tutorials,blog.codersty.com Python Tutorials

As you can see, you want to do the operation in the end parameter, you need to specify the end of the parameter without using the end why I hear it says that because if you do not specify which function in the print () function python takes the bottom line by default.

 

2. Python Print sep Parameter

With the previous parameter, we have shown which operation we will make at the end of the values, so how do we perform different operations between these values and we will do it with the sep parameter. For example, we have the address of a web page;

print("blog", "codersty", "com")

Output is as follows :

blog codersty com

as you can see, Python combines values with spaces, but we didn’t specify it because if we don’t specify anything, Python takes by default a space. We use the same as the sep parameter;

print("blog", "codersty", "com",sep=".")

and output as follows;

blog.codersty.com

 

3. Python Print star(*) Parameter

In this parameter, it allows us to operate between the data such as sep parameter or use character, but in the sep parameter it provides between different variables and elements, and if it allows us to operate on the same variable.

print(*"CoderSty")

If used in the form of output;

C o d e r S t y

This parameter is used in conjunction with the sep parameter.

print(*"CoderSty",sep=".")

use in the;

C.o.d.e.r.S.t.y

an output is made in this way.

 

Print () function; There are more file and flush parameters, since these parameters are the parameters that allow us to process files both unnecessary and confusing you so I will not tell them for now, I will write about these parameters in detail in the course of the files.

Leave a Reply

Your email address will not be published. Required fields are marked *