본문 바로가기
  • 紹睿: 자유롭고 더불어 사는 가치있는 삶

Data67

[python 기초] python의 module에 대하여 module 프로그램 파일 Folder 단위(Directory)로 관리함 = package 1. module 작성 mymath.py """my math""" pi = 3.14159 def area(r): global pi return (pi*r**2) 2. module 이용 from import 를 이용해서 다른 module들을 가져다 쓸수 있음 import mymath print(mymath.area(5)) # 78.53975 print(mymath.pi) # 3.14159 3. 검색경로 python 경로안에 설치 sys.path 변경 PYTHONPATH 이용 .pth 파일 작성 4. Private name 5. Scoping Rule Local > Global > Built-in 2018. 6. 28.
[python 기초] 조건문과 Loop문 + List Comprehension Block 지정- Indentation - level 당 4 spaces 조건문1. 조건지정(Boolean 값)1) False- False, None, 0, "", {}, (), []2) True- True, - False가 아닌 기타의 모든 것 2. 조건실행- if, elif, else 1234567891011121314var = 100if var 2018. 6. 28.
[python 기초] python의 dictionary에 대하여 Ditionary{1:one, 2:two}mapping: key값을 가지고 찾음! 1. 기본적인 사용 방법: {}12345678910111213141516171819202122months = {1:'Jan', 2:'Feb', 3:'Mar', 4:'Apr', 5:'May', 6:'Jun', 7:'Jul', 8:'Aug', 9:'Sep', 10:'Oct', 11:'Nov', 12:'Dec'} print(months[1]) #Jan items = [('name', 'May'), ('birth', 5)]dict_items = dict(items)print(dict_items) # {'name': 'May', 'birth': 5}print(len(dict_items)) # 2 del dict_items['birt.. 2018. 6. 28.
[python 기초] python의 String에 대하여 String문자열 "~~"'~~'"""~~"""- input()을 이용하면 string으로 저장되었었음 1. Raw String: 특수 부호\n (next line)\t (tab만큼 이동)' "r'o': 불가침 영역으로 인정1234567891011121314151617path = "c:\temp"print(path) # c: emp # \를 이용print("c:\\temp") # c:\temp # \ escape sequencepath = 'c:\\program File\\python\\bin'print(path) # c:\program File\python\bin # r''이용print(r'c:\program File\python\bin') #c:\program File\python\bin #Let's.. 2018. 6. 27.
[python 기초] python의 tuple에 대하여 TupleTuple은 ()를 통해 만들거나, ","를 이용하여 만들 수 있다. 123456789101112131415161718192021222324a = 1b = 1,print(type(a), a) # 1print(type(b), b) # (1,) c = 4 * (20+5)d = 4 * (20+5,)print(type(c), c) # 100print(type(d), d) # (25, 25, 25, 25) e = [1, 2, 3]f = tuple(e)print(type(e), e) # [1, 2, 3]print(type(f), f) # (1, 2, 3) print(list('hello')) # ['h', 'e', 'l', 'l', 'o']print(tuple('hello')) # ('h', 'e', 'l.. 2018. 6. 27.
[python 기초] python의 list에 대하여 데이터 구조데이터를 일정한 기준(규칙)에 의해 모아 놓은 것 collection of data elements, structured in some way- built-in + 확장- Container type의 데이터 구조1) Sequence = mapping by element position (index) ex) List, String2) mapping = mapping by element name (key) ex) Dictionary built-in Sequence (내장)1) List2) Tuple3) String4) Buffer objects5) Xrange objects Sequence에 대한 주요 작업1) Indexing: 위치 [0 1 2]2) Slicing: 범위 지정해서 추출3) Add.. 2018. 6. 27.