python

[python] 주석문 | 이스케이프 문자 | 예약어

전감자(◔◡◔) 2022. 9. 19. 22:15

 

1. 주석문

# 한 줄 주석문

'''
멀티 주석문
'''

"""
주석문
"""
 

 

2.-1 이스케이프 문자

#이스케이프 문자 (escape)

print("HelloWorld")
print("Hello\nWorld") # \n은 라인변경
print()
print("Hello    World")
print("Hello\tWorld")#\t은 탭을 3번 입력한 효과
print()

print("Hello\'World")#Hello'World
print('Hello\'World')

print()

print("Hello\"World")#Hello"World
print('Hello\"World')

print()
print("C:\\Python38")#파일경로 지정 시 주로 사용. 하나의 \를 지정해도 가능하지만 OS에 따라서 에러가 발생될 수도 있다.

 

 

2-2. 이스케이프 무시 문자 raw string

# 이스케이프 문자 ( escape )를 무시 ==> raw sting

print("HelloWorld")
print("Hello\nWorld") # \n은 라인변경
print(r"Hello\nWorld")

print()
print("Hello    World")
print("Hello\tWorld")#\t은 탭을 3번 입력한 효과
print(r"Hello\tWorld")
print()

print("Hello\'World")#Hello'World
print('Hello\'World')
print(r'Hello\'World')

print()

print("Hello\"World")#Hello"World # 쌍따옴표 출력
print('Hello\"World')
print(r"Hello\"World")

print()
print("C:\\Python38")#파일경로 지정 시 주로 사용. 하나의 \를 지정해도 가능하지만 OS에 따라서 에러가 발생될 수도 있다.
print(r"C:\\Python38")
 

3. 예약어 출력

 

'''
식별자(identifier)
===> 코드 작성시 사용되는 단어


===> 종류
가. 시스템 정의 식별자


나. 사용자 정의 식별자
-변수명, 함수명, 클래스명등에 사용 가능
-영문자 및 _로 시작, 이후에는 숫자지정 가능
-대소문자 구별

'''

import keyword

print(keyword.kwlist)

'''
['False', 'None', 'True', 'and', 'as', 'assert',
 'async', 'await', 'break', 'class', 'continue',
  'def', 'del', 'elif', 'else', 'except', 'finally', 
  'for', 'from', 'global', 'if', 'import', 'in', 'is',
   'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 
   'return', 'try', 'while', 'with', 'yield']

'''