args:
arg_1 (str) : ..
arg_2 (int, optional) : ...
returns:
bool: ...
# Add a docstring to count_letter()
def count_letter(content, letter):
"""Count the number of times `letter` appears in `content`."""
if (not isinstance(letter, str)) or len(letter) != 1:
raise ValueError('`letter` must be a single character string.')
return len([char for char in content if char == letter])
[function_name].__doc__
docstring = inspect.getdoc(count_letter)
# Open "alice.txt" and assign the file to "file"
with open('alice.txt') as file:
text = file.read()
python에서 with
문은 자원을 반납해야 할 때에 주로 쓰인다.
image = get_image_from_instagram()
# Time how long process_with_numpy(image) takes to run
with timer():
print('Numpy version')
process_with_numpy(image)
# Time how long process_with_pytorch(image) takes to run
with timer():
print('Pytorch version')
process_with_pytorch(image)
refs: https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=wideeyed&logNo=221653260516
decorator
란 무엇인가에 대해@ [decorator_name]
yield
는?yield
는 return
처럼 함수의 리턴값을 주는데, 여러번 줄 수 있다는 차이가 있음.def yield_test():
return list("arg")
def yield_test(arg):
yield "a"
yield "r"
yield "g"