목록2022/01/16 (15)
Developer_Neo
리스트 만들기 리스트 객체 = list( iterable 자료형 ) iterable 자료형 컨테이너 자료형 - 문자열, 튜플, 집합, 사전 내장함수 - range(), reversed(), enumerate(), filter(), map(), zip() 리스트는 mutable객체 연산자 + * in, not in del ''' + ''' >>> L = [1, 3, 5, 7]; M = [2, 4, 6, 8] >>> L + M [1, 3, 5, 7, 2, 4, 6, 8] >>> L, M ([1, 3, 5, 7], [2, 4, 6, 8]) >>> K = L + M >>> K [1, 3, 5, 7, 2, 4, 6, 8] ''' * ''' >>> M = [7, 9] >>> M *= 3 >>> M [7, 9, 7,..
문자열 연산자 + * in, not in del + 문자열은 immutable자료형으로 수정이 불가하다 ex) s[2]='b' - (X) ''' + ''' >>> first_name = 'Hyunho' >>> last_name = 'Jo' >>> full_name = first_name + ' ' + last_name >>> full_name 'Hyunho Jo' ''' * '''' >>> a = 'Hello' >>> a * 3 'HelloHelloHello' >>> greeting 'Hello' >>> a = 'Hello' >>> a *= 3 >>> a # a=a*3 'HelloHelloHello' ''' in, not in ''' >>> words = 'abcdef' >>> 'b' in words T..
빈 문자열 만들기 빈따옴표 이용 str()함수이용 #빈따옴표 이용 s='' print(s) # 결과-> # 아무것도 안나옴 len(s) # 결과: 0 type(s) # 결과: >>> w = str( ) >>> print(w) >>> len(w) 0 >>> type(w) 빈 리스트만들기 빈 대괄호 이용 list()함수이용 >>> a = [] >>> print(a) [] >>> type(a) >>> b = list() >>> print(b) [] >>> type(b) 빈 튜플만들기 빈 소괄호 이용 tuple()함수이용 >>> a=() >>> print(a) () >>> type(a) >>> b=tuple() >>> print(b) () >>> type(b) 빈 사전만들기 빈 중괄호 이용 dict()함수이용 ..
인덱싱(indexing) - 시퀀스 자료형인 문자열, 리스트, 튜플에 사용가능 - 시퀀스 자료형에 부여된 번호를 의미한다. 특징 양수 인덱스 앞에서부터 시작하는 것으로 0부터 시작 음수 인덱스 뒤에서부터 시작하는 것으로 -1부터 시작 문자열 a = 'hello' print(a[0]) # 결과 값: h print(a[1]) # 결과 값: e print(a[2]) # 결과 값: l print(a[3]) # 결과 값: l print(a[4]) # 결과 값: o print(len(a)) # 결과 값: 5 0 1 2 3 4 h e l l o -5 -4 -3 -2 -1 - 양수 인덱스의 맨 마지막은 len(a)-1 이라고 할 수 있고 음수인덱스의 맨 앞은 -len(a)라고 할 수 있다. 리스트 >>> s = 'sh..
print함수 - 출력을 담당하는 것 - 반환값이 없다 따라서 None을 출력한다. >>> y=print('hello') hello >>> print(y) None print함수의 sep, end 옵션 - 구분자(sep)의 디폴트값은 공백이다. - end옵션의 디폴트 값은 개행(줄바꿈)이다 print("hello") # 결과->hello # end옵션의 디폴트 값은 개행 print("a") print("b") ''' 결과 a b ''' # sep옵션의 디폴트 값은 띄어쓰기(공백) print("a", "b", "c") # 결과->a b c # print("문자열", sep 옵션, end 옵션) 형식 print('python', end="_") print('print', end="_") print('end옵..
파이썬의 아홉 가지 자료형 분류 자료형 특징 예 수치 자료형 정수 -3,-2,-1,0,1,2,3 실수 3.14 , 5.5 , 8.0 0.54, -3.89 복소수 3+4j, 5.7+2J , 5+j 부울 자료형 부울 True, False 군집형태 자료형 (컨테이너 자료형) 시퀀스 자료형 문자열 'hello', "python" 리스트 [1,2,3,4], ['red', 'blue'] 튜플 (1,2,3,4), ('red', 'blue') 집합 오름차순으로 정렬됨 기호는 {} {1,2,3}, {'red', 'blue'} 사전 기호 {key: value} {'one': 1, 'two' :2} mutable vs immutable mutable 자료형 - 변경 가능한 자료형 immutable 자료형 - 변경 불가능한 ..
파이썬은 인터프리터가 필요한 언어이다. 이외의 인터프리터가 필요한 언어는 자바스크립트, 파이썬, 루비, sql,... 컴파일러는 C, C++, C#, Go,...에 쓰인다. 자바는 컴파일러와 인터프리터 모두 사용 컴퓨터는 모든 명령을 0과 1로 이해하여 CPU가 처리하고 실행한다. 그래서 우리의 언어인 한글이나 영어는 이진코드로 해석하고 명령을 처리한다 따라서 우리의 언어로 친 코드들을 컴퓨터가 이해할 수 있게 번역해주는 번역기가 필요한데 이 번역기가 인터프리터, 컴파일러이다. 즉 둘 다 고레벨 언어로 작성된 프로그래밍 언어를 기계어로 번역하는 것은 공통점이다. 컴파일러는 전체 소스코드를 보고 명령어를 수집하고 재구성하지만 인터프리터는 소스코드의 각 행을 연속적으로 분석하며 실행한다.( 명령을 한 줄 씩..