.png)
파이썬 아스키()
2022-10-18 last update
6 minutes reading python codenewbie programming tutorial마이코드 |
Python의
예를 들어, 비 ASCII 문자 "¥ "는
산출
아래 예에서는
산출
게시물Python ascii()이 ItsMyCode에 처음 등장했습니다.
Python의
ascii()
는 Strings , Tuples , Lists 등과 같은 객체의 인쇄 가능하고 읽을 수 있는 버전을 반환하는 내장 함수입니다. ascii()
함수는\x,\u를 사용하여 ASCII가 아닌 문자를 이스케이프합니다. 또는\U 이스케이프.ascii() 구문
ascii()
메서드의 구문은 다음과 같습니다.**ascii(object)**
ascii() 매개변수
ascii()
함수는 객체를 인수로 사용합니다. 객체는 Strings , Lists , Tuples 등의 유형이 될 수 있습니다.ascii() 반환 값
ascii()
함수는 개체의 인쇄 가능한 표현을 포함하는 문자열을 반환합니다. ascii()
함수는 *\x,\u 또는\U를 사용하여 비ASCII 문자를 이스케이프합니다. *예를 들어, 비 ASCII 문자 "¥ "는
\xa5
로 출력되고 √는 \u221a
로 출력됩니다.예 1: ascii() 메서드는 어떻게 작동합니까?
ascii()
함수에 여러 줄 텍스트를 전달하는 경우 새 줄의 값이 "\n "이므로 줄 바꿈이 "\n "으로 바뀝니다.
# Normal string
text = 'Hello World'
print(ascii(text))
# Text with Non-ASCII characters
ascii_text = 'Hëllö Wörld !!'
print(ascii(ascii_text))
# Multiline String
multiline_text =''' Hello,
Welcome to
Python Tutorials'''
print(ascii(multiline_text))
산출
'Hello World'
'H\xebll\xf6 W\xf6rld !!'
' Hello,\nWelcome to \nPython Tutorials'
예 2: ascii() 대 print()
아래 예에서는
ascii()
함수와 print()
함수의 차이점을 보여줍니다. ascii()
함수는 ASCII가 아닌 문자를 이스케이프하지만 print()
함수는 값을 이스케이프하지 않고 있는 그대로 인쇄합니다.
# Normal string
text = 'Hello World'
print('ASCII version is ',ascii(text))
print('print version is ',text)
# Text with Non-ASCII characters
ascii_text = 'Hëllö Wörld !!'
print('ASCII version is ',ascii(ascii_text))
print('print version is ',ascii_text)
# Multiline String
multiline_text =''' Hello,
Welcome to
Python Tutorials'''
print('ASCII version is ',ascii(multiline_text))
print('print version is ',multiline_text)
산출
ASCII version is 'Hello World'
print version is Hello World
ASCII version is 'H\xebll\xf6 W\xf6rld !!'
print version is Hëllö Wörld !!
ASCII version is ' Hello,\nWelcome to \nPython Tutorials'
print version is Hello,
Welcome to
Python Tutorials
게시물Python ascii()이 ItsMyCode에 처음 등장했습니다.