logo

print()의 Python 종료 매개변수

기본적으로 Python의 print() 함수는 개행 문자로 끝납니다. C/C++ 배경을 가진 프로그래머는 개행 없이 인쇄하는 방법을 궁금해할 수 있습니다. 파이썬의 print() 함수에는 다음과 같은 매개변수가 제공됩니다. '끝 '. 기본적으로 이 매개변수의 값은 ' ', 즉 새 줄 문자입니다.

예시 1:

여기에서 이 매개변수를 사용하여 임의의 문자/문자열로 인쇄 문을 끝낼 수 있습니다.

파이썬3






# ends the output with a space> print>(>'Welcome to'>, end>=> ' '>)> print>(>'techcodeview.com'>, end>=> ' '>)>

>

>

산출:

Welcome to techcodeview.com>

예시 2:

작업을 시연하는 또 하나의 프로그램 끝 매개변수 .

파이썬3

배우 제나 아만




# ends the output with '@'> print>(>'Python'>, end>=>'@'>)> print>(>'techcodeview.com'>)>

>

>

산출:

[email protected]>

예시 3:

print() 함수는 sep 매개변수를 사용하여 인수를 구분하고 마지막 인수 뒤에서 끝납니다.

파이썬3




print>(>'G'>,>'F'>, sep>=>'>', end='>')> print>(>'G'>)> # provides new line after printing the year> print>(>'09'>,>'12'>,>'2016'>, sep>=>'-'>, end>=>' '>)> > print>(>'Red'>,>'Green'>,>'Blue'>, sep>=>','>, end>=>'@'>)> print>(>'geeksforgeeks'>)>

>

>

산출

GFG 09-12-2016 Red,Green,Blue@geeksforgeeks>

end를 사용하여 문자열 연결:

이 예에서는 end 매개변수를 사용하여 두 개의 print() 문을 단일 출력 행으로 연결합니다. end 매개변수는 첫 번째 print() 문의 공백 문자로 설정되므로 두 번째 print() 문은 같은 줄에서 공백 문자로 구분되어 시작됩니다.

end 매개변수는 다양한 방식으로 출력 형식을 제어하는 ​​데 사용할 수 있는 Python print() 함수의 유용한 기능입니다.

파이썬3




name>=> 'Alice'> age>=> 30> print>(>'My name is'>, name,>'and I am'>, age,>'years old.'>, end>=>' '>)> print>(>'Nice to meet you!'>)>

>

>

산출

My name is Alice and I am 30 years old. Nice to meet you!>