Python

Python Print Function

AKA.DM 2024. 9. 19. 07:34
반응형

The Print Function is one of the mos used functions in Python.

We will now examine the features of this function in depth.

 

Before using a funciton in Python, it is necessary to read the documentation.

Usually, we can acess this document if we write the function in interfaces and press shift + tab in parentheses.

 

 

You can also perform the same operation by putting a question mark in the code cell and typing the function name. 

In this document, we can access a lot of information such as the definiton of a function, wha it does, how to use the parammeters in it.

 

 

Lets start with the values first. We can output as many values as we want by putting commas between them in print function.

 

 

If we write without a comma between the values in the print fucntion, we will get an error.

 

Another of the most used parameters in the print function is the "sep" pararmeter.

Determines the string to be inserted between the values in the output.

The default value of this pararmeter is space.

 

The last parameter of the print function we will examine is the "end" parameter.

This parameter tells Python what to do when we are done with the print function.

By defualt, it is equal to the expression. "\n". The letter "n" here is the abbreviation for newline.

So when we're done with print, the code will switchto a new line.

 

For example, we wrote two print functions below. Since we did not specify the "end" parameter, the default value "\n" worked.

Thus, after the first print, the second print started from a bottom line. 

 

We can change the output by setting the end parameter to a different value.

For example, we have set the end parameter as a  space below. 

So, it printed the second print statement, leaving a space after the first print statement.

 

반응형

'Python' 카테고리의 다른 글

Methods in Strings in Python  (0) 2024.09.24
Boolean Logic Expression in Python  (0) 2024.09.21
Eascape Sequence Opertations in Python  (0) 2024.09.20
Arithmetic Operation in Python  (0) 2024.09.13
Python Type Conversion  (0) 2024.09.11