본문 바로가기

Python4

Regular expression operation (re.sub) re.sub(pattern, repl, string, count=0, flags=0) s = re.sub('[^a-z0-9]','',s) #[a-z0-9] --> matching any lower case letter a to z and digit of 0-9 ''' This will replace any special characters in 's' string with non-space blank characters. ''' -Example- s = 'abc#@%921' s = re.sub('[^a-z0-9]', '', s) s --> 'abc921' https://docs.python.org/3/library/re.html#re.sub re — Regular expression operations .. 2020. 8. 16.
f-string f-string(formated string literal) https://www.python.org/dev/peps/pep-0498/#:~:text=These%20include%20%25%2Dformatting%20%5B1,%5B2%5D%2C%20and%20string.&text=It%20should%20be%20noted%20that,which%20contains%20expressions%20inside%20braces. PEP 498 -- Literal String Interpolation The official home of the Python Programming Language www.python.org index = 1 example = "hello" print(f'{index+1}:{exa.. 2020. 8. 12.
Enumerate Enumerate 함수는 순서가 있는 자료형 (list, set, tuple..) 을 index를 포함한 값으로 리턴한다. a = [5,4,3,2,1] list(enumerate(a)) ---> [(0,5), (1,4), (2,3), (3,2), (4,1)] 인덱스 값을 가지고 있는 값에 자동으로 순차적 부여. 2020. 8. 12.
Type Hint 타입 힌트 (Type Hint) PEP 484 에 있는 문서에 내용이 포함되어 있으며, 파이썬 함수의 파라미터와 리턴값의 type 을 쉽게 볼수 있는 가독성을 살려준다. https://www.python.org/dev/peps/pep-0484/ PEP 484 -- Type Hints The official home of the Python Programming Language www.python.org Example) #function foo takes 'a' paramter as integer and return boolean value def foo(a: int) -> bool: ... 2020. 8. 11.