라벨이 keyword인 게시물 표시

파이썬[Python]: keyword - iskeyword 메서드

keyword 모듈 - iskeyword 메서드(method) /// 설명 파이썬 키워드이면 True 를 반환합니다. ※ 형식 keyword.iskeyword(s) reference https://docs.python.org/3/library/keyword.html#module-keyword /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 import  keyword   print (keyword.iskeyword( 'False' ))   # True print (keyword.iskeyword( 'None' ))   # True print (keyword.iskeyword( 'True' ))   # True print (keyword.iskeyword( 'and' ))   # True print (keyword.iskeyword( 'as' ))   # True print (keyword.iskeyword( 'assert' ))   # True print (keyword.iskeyword( 'async' ))   # True print (keyword.iskeyword( 'await' ))   # True print (keyword.iskeyword( '_' ))   # False   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - softkwlist 변수

keyword 모듈 - softkwlist 변수(variable) /// 설명 파이썬 인터프리터에서 사용하는 모든 소프트 키워드들을 표현합니다. ※ 형식 keyword.softkwlist reference https://docs.python.org/3/library/keyword.html#module-keyword /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 import  keyword   print (keyword.softkwlist) # []   keyword.softkwlist  =   'test' print (keyword.softkwlist)   # test   # Soft Keywords # related identifiers: match, case and _ # https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - nonlocal 키워드

내장함수 - nonlocal 키워드(keyword) /// 설명 중첩함수(nested function)에서 상위 함수의 변수 내용을 변경(encapsulated code) 할 수 있습니다. ※ 형식 nonlocal reference https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-nonlocal_stmt /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 def  func_a():     a  =   "a_string"      def  func_b():         a  =   "func_a_string"      print (a)   # a_string     func_b()      print (a)   # a_string     func_a()   def  func_c():     b  =   "b_string"      def  func_d():         nonlocal b         b  =   "func_b_string"      print (b)   # b_string     func_d()      print (b)   # func_b_string     func_c()   cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - raise 키워드

내장함수 - raise 키워드(keyword) /// 설명 예외(오류)를 발생시킵니다. 실행 후 차례로 주석처리하시면서 확인해 보시기 바랍니다. ※ 형식 raise reference https://docs.python.org/3/tutorial/errors.html https://docs.python.org/3/library/exceptions.html /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 raise # Traceback (most recent call last): #   File "D:\Psychedelphia\Computer_Program\Py\Practice\main.py", line 1, in <module> #     raise # RuntimeError: No active exception to reraise     raise  Exception # Traceback (most recent call last): #   File "D:\Psychedelphia\Computer_Program\Py\Practice\main.py", line 8, in <module> #     raise Exception # Exception     raise  Exception( 'Write Exception' ) # Traceback (most recent call last): #   File "D:\Psychedelphia\Computer_Program\Py\Practice\main.py", line 14, in <module>

파이썬[Python]: keyword - assert 키워드

내장함수 - assert 키워드(keyword) /// 설명 디버깅의 편리성을 위해 사용합니다.(표현(expression)이 False 일 경우 오류를 발생시킵니다.) ※ 형식 assert reference https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-assert_stmt /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 a  =   True assert a   if  a:      print ( 'Not Error' ) else :      print ( 'means Error' )   b  =   1 assert b  > =   0 # assert b < 0, 'b >= 0'  # AssertionError   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - pass 키워드

내장함수 - pass 키워드(keyword) /// 설명 아무런 동작도 하지 않을 경우 사용합니다. ※ 형식 pass reference https://docs.python.org/3/reference/simple_stmts.html /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 def  func_a():  print ( 'function test' )     func_a()   # function test     def  func_b():  pass     # nothing is printed func_b()   #     class  A:      def  func( self ):  print ( 'class A test' )     a  =  A() a.func()   # class A test     class  B:      def  func( self ):  pass     b  =  B() # nothing is printed b.func()   #     class  C:  pass   c  =  C()   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - not 키워드

내장함수 - not 키워드(keyword) /// 설명 논리값을 부정합니다.(참->거짓, 거짓->참) ※ 형식 not reference https://docs.python.org/3/reference/expressions.html#not /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 a  =   True print (a)   # True print ( not  a)   # False   b  =   'string' print (b)   # string print ( not  b)   # False print ( not   not  b)   # True   c  =   '' print (c)   # print ( not  c)   # True print ( not   not  c)   # False   d  =   1 print (d)   # 1 print ( not  d)   # False   if  b  is   not  c:      print ( 'b is string' )   # b is string else :      print ( 'empty' )   print ( 'b is string'   if  b  is   not  c  else   'empty' )   # b is string   print ( 's'   in   'string' )   # True print ( 's'   not   in   'string' )   # False   print ( 'In'   if   's'   in   'string'   else   'None' )   # In print ( 'None'  

파이썬[Python]: keyword - or 키워드

내장함수 - or 키워드(keyword) /// 설명 하나 이상의 값이 참일 경우 참(True)을 반환합니다.(모든 값이 False 일 경우 False) ※ 형식 or reference https://docs.python.org/3/reference/expressions.html#or /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 a  =   False b  =   False   x  =  a  or  b   print (x)   # False   if  x:      print ( 'x is True' ) else :      print ( 'x is False' )   # x is False   c  =   True   y  =  a  or  b  or  c   print (y)   # True   print ( 'y is True'   if  y  else   'y is False' )   # y is True # test = 'y is True' if y else 'y is False' # print(test)   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - and 키워드

내장함수 - and 키워드(keyword) /// 설명 모든 값이 참일 경우 참(True)을 반환합니다. ※ 형식 and reference https://docs.python.org/3/reference/expressions.html#and /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 a  =   True b  =   True   x  =  a  and  b   print (x)   # True   if  x:      print ( 'x is True' )   # x is True else :      print ( 'x is False' )   c  =   False   y  =  a  and  b  and  c   print (y)   # False   print ( 'y is True'   if  y  else   'y is False' )   # y is False # test = 'y is True' if y else 'y is False' # print(test)   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: keyword - kwlist 변수

keyword 모듈 - kwlist 변수(variable) /// 설명 파이썬 인터프리터에서 사용하는 모든 키워드들을 표현합니다. ※ 형식 keyword.kwlist reference https://docs.python.org/3/library/keyword.html#module-keyword /// 예제 1 2 3 4 5 6 7 8 import  keyword   print (keyword.kwlist) # ['False', 'None', 'True', '__peg_parser__', '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']   keyword.kwlist  =   'test' print (keyword.kwlist)   # test   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬