Python/Python 기초 정리(16)
-
[Python] 문자열 관련 함수 : 문자 포함 관련 함수
문자 포함 관련 함수 startswith() / endswith() 문자(열)가 검사하고자 하는 문자(열)로 시작/끝 부분과 매칭 하는지의 여부를 boolean값으로 반환한다 {문자(열)}.startswith("{문자(열)}") {문자(열)}.endswith("{문자(열)") a = "Hello, Welcome to the Python World" print("a.startswith('H') >> ", a.startswith('H')) print("a.startswith('Hello, W') >> ", a.startswith('Hello, W')) print("a.startswith('Hello, W') >> ", a.startswith('el')) print("a.endswith('H') >> ", a..
2022.03.19 -
[Python] 문자열 관련 함수 : 문자열 계산 관련
문자열 계산 관련 메서드 len() 문자열의 길이를 반환한다 s = 'asdfg' print(len(s)) 결과 13 min() / max() 문자열 내 문자, 혹은 숫자의 최솟값/최댓값 문자와 숫자가 함께 있으면 문자가 숫자보다 큰 값으로 인식한다 a = 'asdf' print("min('asdf') >> ", min(a)) print("max('asdf') >> ", max(a)) b = '82917' print("min('82917') >> ", min(b)) print("max('82917') >> ", max(b)) c = 'asd54cv231' print("min('asd54cv231') >> ", min(c)) print("max('asd54cv231') >> ", max(c)) d = 82..
2022.03.19 -
[Python] 문자열 관련 함수
capitalize() 첫글자를 대문자로 만들어준다 v_str = "niceman nice" print("Capitalize: ", v_str.capitalize()) # >>> Capitalize: Niceman nice endswitch({문자}) 마지막 문자를 비교하여 bool값을 리턴한다 v_str = "Orange" print("endswith?: ", v_str.endswith("s")) # >>> False print("endswith?: ", v_str.endswith("ge")) # >>> True join([{앞},{뒤}]) 문자 앞 뒤에 값을 입력한다. v_str = "Niceman" print("join str: ", v_str.join(["I'm ", "!"])) # >> join..
2022.03.14 -
[Python] 문자열 관련 내용 정리
문자열 생성 # 문자열 생성 str1 = "I am Boy." str2 = 'NiceMan' str3 = """How are you?""" str4 = '''Thank you!''' 타입 출력 str1 = "a" print(type(str1)) # 결과 문자열 길이 str1 = "a" print(len(str1)) # 결과 1 빈 문자열 생성 # 빈 문자열 str_t1 = '' str_t2 = str() 이스케이프 문자 사용 # 이스케이프 문자 사용 escape_str1 = "Do you have a \"big collection\"?" escape_str2 = 'What\'s on TV?' escape_str3 = "What's on TV?" escape_str4 = 'This is a "book".'..
2022.03.14 -
[Python] 데이터 타입 정리 : string, bool, int, float, list, dict, set, tuple
타입 출력하기 print(type(v_str)) 데이터 길이 출력하기 # 튜플 : 자료 개수 print(len((1, 3, 4))) # 리스트 : 자료 개수 print(len([1, 3, 4])) # 세트 : 자료 개수 print(len({1, 3, 4})) # 사전형 : 자료 개수 print(len({"x": 1, "c": 3, "d": 4})) # 문자형 : 문자 길이 print(len("asdasd")) # 정수형 : 불가 # print(len(32)) # 실수형 : 불가 # print(len(32.23)) # 불리언 : 불가 # print(len(True)) String 문자형 v_str = "NiceMan" Boolean 불리언 v_bool = True Float 실수형 v_float = 10...
2022.03.14 -
[Python] 기초 문법 정리
import import this import sys 캐릭터 셋 확인 # Python 3.x 입력 인코딩 print(sys.stdin.encoding) # Python 3.x 출력 인코딩 print(sys.stdout.encoding) 출력문 # 출력문 print("My name is Goodboy!") 변수 선언 방식 # 변수 선언 myName = "Goodboy" 조건문 # 조건문 if isOk == "OK": print("OK") elif isOk == "NOT OK": print("NOT OK") else : print("ERROR") 반복문 # 반복문(구구단) for i in range(1, 10): for j in range(1, 10): print('%d * %d = ' % (i, j), i..
2022.03.14