프로그래밍
-
회문 판별과 N-gram 만들기Python 2023. 10. 11. 16:58
회문 판별 회문: 거꾸로 읽어도 제대로 읽은 것과 같은 단어와 문장 ex) level, sos... etc # 반복문으로 문자 검사 word = input('단어 입력: ') is_palindrome = True for i in range(len(word) // 2): if word[i] != word[-1 - i]: is_palindrome = False break print(is_palindrome) # 실행 결과 단어 입력: hello (입력) False 단어 입력: level (입력) True N-gram 만들기 N-gram: 문자열에서 N개의 연속된 요소를 추출하는 방법 text = 'hello' # 2-gram이므로 문자열의 끝에서 한 글자 앞까지만 반복 for i in range(len(te..
-
filePython 2023. 10. 11. 15:09
파일에 문자열 쓰기, 읽기 # 파일 쓰기 file = open('hello.txt', 'w') file.write('Hello, world!') file.close() # 파일 읽기 f = open('hello.txt', 'r') s = f.read print(s) f.close() # 자동으로 파일 객체 닫기 with open('hello.txt', 'r') as f: s = f.read() print(s) 문자열 여러 줄을 파일에 쓰기, 읽기 # 반복문으로 문자열 여러 줄을 파일에 쓰기 with open('hello.txt', 'w') as file: for i in range(3): file.write( 'Hello, world! {0}\n'.format(i) ) Hello, world! 0 # 출..
-
setPython 2023. 10. 11. 14:04
집합을 표현하는 세트(set) 자료형으로 합집합, 교집합, 차집합 등의 연산 가능 >>> fruits = {'strawberry', 'grape', 'orange', 'pineapple', 'cherry'} >>> fruits {'cherry', 'pineapple', 'strawberry', 'grape', 'orange'} >>> fruits = {'orange', 'orange', 'cherry'} >>> fruits {'cherry', 'orange'} 요소의 순서가 정해져 있지 않아 출력할 때마다 요소의 순서가 다르게 나옴 요소 중복될 수 없음 >>> fruits['cherry'] Traceback (most recent call last): File "", line 1, in TypeError..
-
딕셔너리 응용Python 2023. 10. 10. 17:27
딕셔너리 만들기 기본 >>> d1 = dict( name='cat', age=3 ) >>> print(d1) {'name': 'cat', 'age': 3} >>> >>> d2 = dict( zip(['name', 'age'], ['cat', 3]) ) >>> print(d2) {'name': 'cat', 'age': 3} >>> >>> d3 = dict( [('name', 'cat'), ('age', 3)] ) >>> print(d3) {'name': 'cat', 'age': 3} >>> >>> d4 = dict( {'name':'cat', 'age':3} ) >>> print(d4) {'name': 'cat', 'age': 3} 딕셔너리 응용 >>> # 딕셔너리에 키-값 쌍 추가, 기본값 저장 >>> ..
-
문자열 응용Python 2023. 10. 10. 12:45
문자열 조작 >>> # 문자열 바꾸기 replace('바꿀문자열', '새문자열') >>> 'Hello, world!' .replace('world', 'Python') 'Hello, Python!' >>> # 바꾼 문자열 유지 >>> s = 'Hello, world!' >>> s = s.replace('world', 'Python') >>> print(s) Hello, Python! >>> >>> # 문자 바꾸기 str.maketrans('바꿀문자', '새문자') >>> table = str.maketrans('aeiou', '12345') >>> 'apple'.translate(table) '1ppl2' >>> >>> # 문자열 분리하기 >>> 'apple pear grape pineapple oran..
-
CSS3 속성HTML 2023. 10. 6. 17:37
박스 속성 margin 속성 테두리와 다른 태그 사이의 테두리 바깥쪽 여백 border 속성 테두리 padding 속성 테두리와 글자 사이의 테두리 안쪽 여백, 배경색은 padding 영역까지만 적용 width 속성 글자를 감싸는 영역의 가로 크기 height 속성 글자를 감싸는 영역의 세로 크기 전체 너비 = width+ 2x(margin+border+padding) 전체 높이 = height+ 2x(margin+border+padding) width, height 적용 margin, padding 속성 적용 흰 margin 검 border 빨 padding 네 방향 속성 지정 두 방향씩 속성 지정 Lorem ipsum dolor amet 기본 테두리 만들기 둥근 테두리 border-radius: 20..
-
CSS3 기초: 선택자와 단위HTML 2023. 10. 5. 17:30
css 선택자 종류 http://www.w3.org/TR/CSS CSS Snapshot 2023 Abstract This document collects together into one definition all the specs that together form the current state of Cascading Style Sheets (CSS) as of 2023. The primary audience is CSS implementers, not CSS authors, as this definition includes modules by sp www.w3.org 종류 형태 설명 전체 선택자 * HTML 페이지 내부의 태그 모두 선택 태그 선택자 태그 HTML 페이지 내부의 특정 태그 모두 선택 아..
-
HTML 입력 양식 태그, 구조화HTML 2023. 10. 5. 14:57
입력 양식 태그 HTML5 문서 구조화 공간 분할 태그 블록 형식 태그 인라인 형식 태그 div 태그 span 태그 h1~h6 태그 a 태그 p 태그 input 태그 목록 태그 글자 형식 태그 테이블 태그 입력 양식 태그 시맨틱 태그 태그 설명 header 머리말(페이지 제목, 페이지 소개) nav 하이퍼링크들을 모아 둔 내비게이션 aside 본문 흐름에 벗어나는 노트나 팁 section 문서의 장이나 절에 해당하는 내용 article 본문과 독립적인 콘텐츠 영역 footer 꼬리말(저자나 저작권 정보) 텍스트 가운데 정렬 div 안에 text-align: center; 표 가운데 정렬 table 안에 margin-left: auto;margin-right: auto; 회원가입 서식 작성 회원등록 회원가..