프로그래밍
-
리스트와 튜플 응용Python 2023. 10. 4. 16:05
리스트 요소 추가 insert( 0, 요소 ): 리스트 맨 처음에 요소 추가 insert( len(리스트), 요소 ): 리스트 끝에 요소 추가 리스트 요소 삭제 첫 번째 줄: collections 모듈에서 deque를 가져옴 a.append(n): 덱의 오른쪽에 n 추가 a.popleft(): 덱의 왼쪽 요소 하나 삭제 index로 가장 처음 찾은 20의 인덱스를 구함 리스트 요소 정렬 sort() 또는 sort(reverse=False): 리스트 값을 작은 순서대로(오름차순) sort(reverse=True): 리스트 값을 큰 순서대로 정렬(내림차순) 리스트의 모든 요소 삭제 리스트를 슬라이스로 조작하기 값이 한 개 들어 있는 리스트를 할당하면 a.append(), a.extend()와 같음 리스트의 ..
-
FizzBuzz와 터틀 그래픽스Python 2023. 9. 27. 17:27
규칙 1. 1에서 100까지 출력 2. 3의 배수는 Fizz 출력 3. 5의 배수는 Buzz 출력 4. 3과 5의 공배수는 FizzBuzz 출력 코드 골프 방식으로 작성된 예제 코드 골프: 문자 수를 최대한 줄여 작성한 코드 → 코드의 문자 수를 얼마나 줄일 수 있는지 겨루는 놀이 혹은 여러 가지 방식 중 하나일 뿐 → 실무에서 이런 방식으로 작성하면 본인 포함 여러 사람 고생하게 됨 복권 숫자 뽑는 코드 터틀 그래픽스 점점 크기도 커지고 원에 가까워짐 색은 구글에서 'color picker' 검색 시 편하게 코드 딸 수 있음
-
딕셔너리, if 조건문Python 2023. 9. 25. 17:25
딕셔너리 키: 문자열, 정수, 실수, 불 등 사용 가능, 자료형 섞어서 사용 가능 값: 리스트, 딕셔너리 포함한 모든 자료형 사용 가능 → 키에는 리스트, 딕셔너리 사용 불가능 if 조건문 if 조건식: 코드(들여쓰기 4칸) if 조건문은 if에 조건식을 지정하고 :(콜론)을 붙이며 다음 줄에 실행할 코드가 오고, 이때 실행할 코드는 반드시 들여쓰기 파이썬에서 :(콜론)이 나오면 그 다음 줄부터는 무조건 들여쓰기 들여쓰기 하지 않으면 에러 조건문 안에 있는 들여쓰기 깊이 맞춰야 함 들여쓰기가 맞지 않아 조건문과 관계 없는 '끝입니다'만 출력 pass: 아무 일도 하지 않는 코드, 넣어 두고 나중에 할 일은 주석으로 남겨 놓는 방식 TODO, FIXME, BUG, NOTE 등 일관된 주석 사용 else 사..
-
시퀀스 자료형 확인하기Python 2023. 9. 25. 15:51
in 연산자를 사용해서 있으면 True, 없으면 False 출력 not in 연산자 특정 값이 없으면 True, 있으면 False 출력 튜플, range, 문자열도 같은 방법으로 활용 가능 시퀀스 객체 반복하기 (0 또는 음수를 곱하면 빈 객체가 나오며 실수는 곱할 수 없음) · 시퀀스 객체 * 정수 · 정수 * 시퀀스 객체 · range는 + 연산자로 연결할 수 없듯 * 연산자 이용해 반복 불가능 → 리스트 or 튜플로 만들어 반복 가능 · 문자열은 * 연산자 사용해 반복 가능 문자열의 길이는 공백까지 포함, 한글 문자열도 len으로 구할 수 있음 UTF-8에서 한글 글자 하나는 3 바이트로 표현하므로 실제 바이트 수 15 인덱스 사용 요소에 값 할당하기 시퀀스 객체는 []로 요소에 접근한 뒤 =로 값..
-
HTML5 기본HTML 2023. 9. 21. 17:30
인터넷: 전 세계를 연결하는 국제 정보 통신망 · 컴퓨터나 스마트폰 같은 디지털 기기로 연결되어 정보를 공유하는 공간 웹: 인터넷 공간에서 제공하는 서비스 클라이언트(사용자): 요청하는 쪽, 웹 페이지를 제공받는 일반 사용자 서버(제공자): 응답하는 쪽, 네이버나 다음 등 웹 서비스를 제공하는 기업 서버 프로그램: 사용자와 먼 곳에 있으므로 백 엔드 프로그램 클라이언트 프로그램: 사용자와 가까운 곳에 있기 때문에 프런트 엔드 프로그램 HTML5 기본 용어 태그와 요소 요소: HTML 페이지를 구성하는 각 부품 · 제목, 본문, 이미지 등이 모두 요소 · 자바스크립트 개발에서는 요소를 객체(object)라고도 함 태그: 요소를 만들 때 사용하는 작성 방법 · 흔히 요소와 태그를 구분하지 않고 사용 내용을 ..
-
리스트와 튜플Python 2023. 9. 20. 17:11
리스트와 튜플 증가폭은 음수도 가능, 해당 값만큼 숫자 줄어듦 문자열이나 실수는 range에 넣을 수 없음 튜플은 읽기 전용 리스트 (리스트는 저장된 요소 변경 및 추가, 삭제 가능) 값 한 개를 괄호로 묶은 경우 그냥 값 ,(콤마)를 붙여야 튜플이 됨 위 사진에서 주석으로 달아 뒀던 문제인데, 리스트 입력할 때처럼 대괄호 대신 괄호 하나 더 넣어 주면 결과 값 정상 출력 앞서 사용했던 input().split()은 리스트를 반환해 리스트 언패킹 형식으로 입력 값을 변수 여러 개에 저장할 수 있음