<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>hs_0919.log</title>
        <link>https://velog.io/</link>
        <description>꾸준히 정리해서 공부한것을 올려보자!</description>
        <lastBuildDate>Tue, 14 Mar 2023 05:17:52 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <copyright>Copyright (C) 2019. hs_0919.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/hs_0919" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Python - 14]]></title>
            <link>https://velog.io/@hs_0919/Python-14</link>
            <guid>https://velog.io/@hs_0919/Python-14</guid>
            <pubDate>Tue, 14 Mar 2023 05:17:52 GMT</pubDate>
            <description><![CDATA[<blockquote>
<h2 id="함수--argument와-parameter-키워드로-matching-하기">함수 : argument와 parameter 키워드로 matching 하기</h2>
</blockquote>
<blockquote>
<p>매개변수 유형</p>
</blockquote>
<ul>
<li>위치 매개변수 : 인수와 순서대로 대응 </li>
<li>*a : 가변 인수 위치를 나타냄, 이 매개 변수는 함수에 전달된 위치 인수를 튜플 형태로 수집합니다.</li>
<li>sbs(1, 2, 3)을 호출하면, a는 1이 되고, tu는 (2, 3)이 됩니다.</li>
<li>기본값 매개변수 : 매개변수에 입력값이 없으면 기본값 사용</li>
<li>키워드 매개변수 : 인수와 매개변수를 동일 이름으로 대응</li>
<li>가변 매개변수 : 인수의 갯수가 동적인 경우, **di는 가변 키워드 인수를 나타냅니다. 이 매개 변수는 함수에 전달된 키워드 인수를 딕셔너리 형태로 수집합니다.</li>
<li>sbs(1, b=2, c=3)을 호출하면, a는 1이 되고, tu는 ()이 되고, di는 {&#39;b&#39;: 2, &#39;c&#39;: 3}이 됩니다.</li>
</ul>
<ol>
<li><pre><code>def showGugu(start, end=5):
 for dan in range(start, end+1):
     print(str(dan)+&#39;단 출력&#39;)
</code></pre></li>
</ol>
<p>showGugu(2,3)
print()
showGugu(3)
print()
showGugu(start=2, end=3)
print()
showGugu(end=3, start=2) # 서로 바뀌어도 똑같이 출력, 이름따라 간다.
print()
showGugu(2, end=3) # 이렇게 써도 결과는 같다
print()</p>
<h1 id="showgugustart2-3--이건-에러가-발생한다">showGugu(start=2, 3) # 이건 에러가 발생한다.</h1>
<p>print()</p>
<h1 id="showguguend3-start2--이것도-에러가-발생--2두번째-인수를-상수로-주면-에러가-발생한다">showGugu(end=3, start=2) # 이것도 에러가 발생 , @@2두번째 인수를 상수로 주면 에러가 발생한다.@@</h1>
<pre><code>2. </code></pre><p>print(&#39;\n가변인수 처리&#39;)
def func1(*ar):
    #print(ar)
    for i in ar:
        print(&#39;밥 : &#39;+i)</p>
<p>print()
func1(&#39;비빔밥&#39;, &#39;공기밥 하나요&#39;)
func1(&#39;비빔밥&#39;, &#39;공기밥 하나요&#39;,&#39;김치 더주세요&#39;)</p>
<p>def func2(a, <em>ar):
#def func2(</em>ar, a): # 에러 발생, 패킹 연산자는 앞에다 적으면 에러발생, 뒤에다 적어야 한다.
    print(a)
    for i in ar:
        print(&#39;밥 : &#39;+i)</p>
<p>print()
func2(&#39;비빔밥&#39;, &#39;공기밥 하나요&#39;)
func2(&#39;비빔밥&#39;, &#39;공기밥 하나요&#39;,&#39;김치 더주세요&#39;)</p>
<p>print()
def calcProcess(op, *ar):
    if op == &#39;sum&#39;:
        re = 0
        for i in ar:
            re += i</p>
<pre><code>elif op == &#39;mul&#39;:
    re = 1
    for i in ar:
        re *= i
return re</code></pre><p>print(calcProcess(&#39;sum&#39;, 1,2,3,4,5))
print(calcProcess(&#39;mul&#39;, 1,2,3,4,5))</p>
<pre><code>3. </code></pre><p>def func3(w, h, *<em>other): # *</em> - db연동할때 많이 사용한다 기억해야 한다.
    print(&#39;w:{}, h:{}&#39;.format(w, h))
    print(other)</p>
<p>func3(55, 160)
func3(55, 160, name=&#39;홍길동&#39;) # {} dict 로 넣으면 안된다.{name=&#39;홍길동&#39;}-err
func3(55, 160, name=&#39;홍길동&#39;, age=23)</p>
<p>print()
def func4(a,b,<em>c,*</em>d):
    print(a,b)
    print(c)
    print(d)
func4(1,2)
func4(1,2,3) # 데이터하나 있을때 (3,) 튜플이고 콤마가 있다.(?)
func4(1,2,3,4,5)
func4(1,2,3,4,5, x=6,y=7) # **d -&gt; {&#39;x&#39;: 6, &#39;y&#39;: 7} 이런 모습으로 나옴....</p>
<p>*v1, v2, v3 = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5}
print(v1)
print(v2)
print(v3)</p>
<p>```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 13]]></title>
            <link>https://velog.io/@hs_0919/Python-13</link>
            <guid>https://velog.io/@hs_0919/Python-13</guid>
            <pubDate>Tue, 14 Mar 2023 05:06:30 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>변수에 생존 범위, 생존 시간 (scope rule)</p>
</blockquote>
<ul>
<li>변수 접근 순서 : Local &gt; Enclosing function &gt; Global</li>
</ul>
<pre><code>player = &#39;전국대표&#39;   # 전역변수 

def funcSoccer():
    name=&#39;신기해&#39;    # 지역변수
    print(name, player)

funcSoccer()
print(player)

print(&#39;-----------&#39;)
a=10; b=20; c=30; #전역변수
print(&#39;1) a:{}, b:{}, c:{}&#39;.format(a,b,c)) # a=10; b=20; c=30;
def func1():
    a =40
    b =50
    c =100
    def func2():
        func2_local = 7
        global c # c는 전역변수로 바뀜 
        nonlocal b # b는 func1으로 올라감
        print(&#39;2) a:{}, b:{}, c:{}&#39;.format(a,b,c)) # func1()- 기존값 a=40 ,b=50, c=30(global c로인하여 전역변수로 바뀜, 그래서 100이 아니라 30이다.) 
        c =60 # err : local variable &#39;c&#39; referenced before assignment
              # global c-&gt; c는 전역변수로 바뀌어서 기존 전역변수 c 값 30이 60바뀜.
        b =70 # nonlocal b -&gt; b는 func1()의 b 값으로 되어서 기존 b의 값 50이 70으로 바뀜 
    func2()
    print(&#39;3) a:{}, b:{}, c:{}&#39;.format(a,b,c)) # func1()- a=40, b=70, c=100
func1()
print(&#39;함수 수행 후) a:{}, b:{}, c:{}&#39;.format(a,b,c)) # 글로벌 변수(전역변수)- a=10, b=20, c=60</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 12]]></title>
            <link>https://velog.io/@hs_0919/Python-12</link>
            <guid>https://velog.io/@hs_0919/Python-12</guid>
            <pubDate>Tue, 14 Mar 2023 04:58:44 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>function(함수)</p>
</blockquote>
<ul>
<li>여러 개의 수행문을 하나의 이름으로 묶은 실행단위(unit)</li>
<li>반복 소스의 재활용(단순화)</li>
<li>디버깅이 쉽다. -&gt; 유지 보수비가 적게 든다.</li>
<li>내장함수, 사용자 정의함수</li>
</ul>
<ol>
<li>내장함수 : maker가 제공<pre><code>a=3
print(a)
print(sum([3,5]))
print(bin(8))
print(int(1.6), float(3))
</code></pre></li>
</ol>
<p>a = 10
b = eval(&#39;a+5&#39;)
print(b)</p>
<pre><code>
2. </code></pre><p>print(round(1.2), round(1.6))
import math
print(math.ceil(1.2), math.ceil(1.6)) # 정수 근사치 중 큰 수
print(math.floor(1.2), math.floor(1.6)) # 정수 근사치 중 작은 수</p>
<p>print()
b_list =[True, 1, False]
print(all(b_list)) # 모든 값이 참이면 참
print(any(b_list)) # 하나라도 참이면 참</p>
<p>b_list =[1,2,3,4,5,7,16]
print(all(a&lt;10 for a in b_list)) # b_list에서 하나씩 꺼내서 10보다 작은지 확인
print(any(a&lt;10 for a in b_list))</p>
<p>print()
x=[10,20,30]
y=[&#39;a&#39;, &#39;b&#39;]
for i in zip(x,y):
    print(i)</p>
<pre><code>
3. 함수 만들기, def 함수명(매개변수, ....): ~~</code></pre><p>print(&#39;뭔가를 하다가...&#39;)</p>
<p>def DoFunc1():   # 함수의 생성
    print(&#39;DoFunc1 수행&#39;)
    # return None # 생략</p>
<p>print(&#39;뭔가를 하다가 2...&#39;)<br>DoFunc1() # 함수 호출
print(&#39;뭔가를 하다가 2...&#39;)<br>DoFunc1() # 함수 호출</p>
<p>print(DoFunc1)  # 파이썬은 대,소문자 구애받지 않는다.
DoFunc2 = DoFunc1  # 주소 치환
DoFunc2()</p>
<p>print(DoFunc1()) # 함수문을 수행하면 리턴값이 반드시 있다. 기본 None 리턴</p>
<pre><code>4. </code></pre><p>def DoFunc3(para1, para2):</p>
<h1 id="pass">pass</h1>
<p>   result = para1 + para2</p>
<h1 id="printresult">print(result)</h1>
<p>   return result</p>
<p>print(DoFunc3(10, 20))
aa = DoFunc3(10, 20)<br>print(aa)
print(id(DoFunc3), DoFunc3, DoFunc3(1,2))
print(&#39;현재 파일(모듈)이 사용중인 객체 목록 : &#39;, globals())</p>
<p>print(DoFunc3(&#39;대한&#39;, &#39;민국&#39;))</p>
<h1 id="printdofunc3대한-2--type-error---타입이-안맞아서">print(DoFunc3(&#39;대한&#39;, 2)) # Type Error - 타입이 안맞아서</h1>
<h1 id="printdofunc31--missing-error---1개만-써서">print(DoFunc3(1)) # Missing Error - 1개만 써서</h1>
<h1 id="printdofunc3123--missing-error---2개인데-3개-써서">print(DoFunc3(1,2,3)) # Missing Error - 2개인데 3개 써서</h1>
<pre><code>5.</code></pre><p>def DoFunc4(arg1, arg2):
    if (arg1 + arg2) % 2 == 1:
        return
    else:
        aa =DoFunc5(arg1, arg2) # 함수 내에서 다른 함수 호출
        print(aa)</p>
<p>def DoFunc5(arg1, arg2):
    return arg1 + arg2</p>
<p>DoFunc4(5,6)
DoFunc4(5,5)</p>
<p>print()
def swapfunc(a,b):
    return b,a  # 하나 리턴함, 두개처럼 보이지만 한개를 리턴한다
                # tuple type 으로 묶여 하나의 값으로 반환
    # return (b,a)
    # return [b,a]</p>
<pre><code>6. </code></pre><p>a=10; b=20;
print(swapfunc(a,b)) # 반환값 - tuple</p>
<p>print()
def func1():
    print(&#39;func1 함수 멤버&#39;)
    def func2():
        print(&#39;func1의 내부 함수인 func2 멤버&#39;)
    func2()
func1()</p>
<pre><code>
7. </code></pre><h1 id="if-조건식-안에-함수-사용">if 조건식 안에 함수 사용</h1>
<p>def isOdd(para):
    return para % 2 == 1 
print(isOdd(5))
print(isOdd(6))
print(isOdd(7))</p>
<p>mydict = {x:x*x for x in range(11) if isOdd(x)}
print(mydict)</p>
<pre><code>
8. 함수 연습용 게임</code></pre><p>print(&#39;함수 연습용 게임 --- &#39;)
import random
import time</p>
<p>def gameStart():
    print(&#39;보물을 찾아 여행을 떠나자. 동굴 문은 두개다&#39;)
    print(&#39;동굴 속에는 착한 용과 무서운 용이 있다.&#39;)
    print(&#39;랜덤하게 동굴을 선택해 용을 만나면 보물을 획득하고, 나쁜 용을 만나면 죽습니다.&#39;)</p>
<p>def chooseCave():
    cave=&#39;&#39;
    while cave!= &#39;1&#39; and cave != &#39;2&#39;:
        print(&#39;동굴을 선택(1 또는 2)&#39;)
        cave = input()
    return cave
def chkCave(selectNum):
    print(&#39;동굴에 도착했습니다&#39;)
    time.sleep(3)
    rndNum = random.randint(1, 2)</p>
<pre><code>if selectNum ==str(rndNum):
    print(&#39;착한용을 만났지만 보물을 얻지 못했어요. 보물을 얻을 확률은 3%에요&#39;)
else:
    print(&#39;죽었습니다.&#39;)</code></pre><p>playAgain=&#39;y&#39;
while playAgain == &#39;y&#39;:
    gameStart()
    caveNumber = chooseCave()
    chkCave(caveNumber)
    print(&#39;계속 할까요?(y or n)&#39;)
    playAgain = input()
```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 11]]></title>
            <link>https://velog.io/@hs_0919/Python-11</link>
            <guid>https://velog.io/@hs_0919/Python-11</guid>
            <pubDate>Tue, 14 Mar 2023 04:37:08 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>추상 클래스(추상 메소드) - 자식 클래스에서 부모의 메소드의 이름을 강요하도록 함</p>
</blockquote>
<pre><code>from abc import * 

class AbstractClass(metaclass = ABCMeta): # 추상 클래스가 됨.

    @abstractmethod
    def myMethod(self): # 추상 메소드가 됨
        pass

    def normalMethod(self):
        print(&#39;추상 클래스는 일반메소드를 가질 수 있다.&#39;)

# parent = AbstractClass() # err - Can&#39;t instantiate abstract class

class Child1(AbstractClass):
    name = &#39;난 Child1&#39;

    def myMethod(self):
        print(&#39;Child1에서 추상 메소드에 내용을 적용&#39;)

c1 = Child1()
print(c1.name)
c1.myMethod()
c1.normalMethod()



print()
class Child2(AbstractClass):
    def myMethod(self):
        print(&#39;Child2에서 추상의 마법을 풀다&#39;)
        print(&#39;이제는 자유다&#39;)

    def normalMethod(self):
        print(&#39;추상 클래스의 일반 메소드는 오버라이딩이 선택적이다.&#39;)

    def good(self):
        print(&#39;Child2 고유 메소드&#39;)

c2 = Child2()
c2.myMethod()
c2.normalMethod()
c2.good()

print(&#39;---------------------&#39;)

imsi = c1
imsi.myMethod()
print()
imsi = c2
imsi.myMethod()

print(&#39;----------------------------------------------&#39;)

from abc import *

class Employee(metaclass = ABCMeta):

    def __init__(self, irum, nai):
        self.irum = irum
        self.nai= nai

    @abstractmethod
    def pay(self): #추상 메소드가 됨
        pass

    @abstractmethod
    def data_print(self):
        pass

    def irumnai_print(self):
        pass

print(&#39; Temporary &#39;)

class Temporary(Employee):
    def __init__(self, irum, nai , ilsu, ildang):
        self.ilsu = ilsu
        self.ildang = ildang
        Employee.__init__(self, irum, nai)

    def pay(self):
        return self.ilsu*self.ildang

    def data_print(self):
        print(&#39;이름 : {}, 나이 : {}, 월급 : {}&#39;.format(self.irum, self.nai, str(self.pay())))

class Regular(Employee):
    def __init__(self, irum, nai, salary):
        super().__init__(irum, nai)
        self.salary = salary

    def pay(self):
        return self.salary

    def data_print(self):
        print(&#39;이름 : {}, 나이 : {}, 급여 : {}&#39;.format(self.irum, self.nai, str(self.pay())))


class Salesman(Regular):
    def __init__(self, irum, nai, salary, sales, comission):
        super().__init__(irum, nai, salary)
        self.sales = sales
        self.comission = comission
    def pay(self):
        return super().pay() + (self.sales*self.comission)

    def data_print(self):
        print(&#39;이름 : {}, 나이 : {}, 수령액 : {}&#39;.format(self.irum,self.nai,str(self.pay())))


t = Temporary(&#39;홍길동&#39;, 25, 20, 150000)
r = Regular(&#39;한국인&#39;, 27,3500000)
s = Salesman(&#39;손오공&#39;, 29,1200000, 50000000, 0.25)

t.data_print() # 이름 : 홍길동, 나이 : 25, 월급 : 3000000
r.data_print() # 이름 : 한국인, 나이 : 27, 급여 : 3500000
s.data_print() # 이름 : 손오공, 나이 : 29, 수령액 : 13700000.0</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 10]]></title>
            <link>https://velog.io/@hs_0919/Python-10-tdptnt17</link>
            <guid>https://velog.io/@hs_0919/Python-10-tdptnt17</guid>
            <pubDate>Tue, 14 Mar 2023 04:20:33 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>method override(재정의)</p>
</blockquote>
<pre><code>class Parent:
    def printData(self):
        pass

class Child1(Parent):
    def printData(self):    # method override
        print(&#39;Child1에서 재정의&#39;)


class Child2(Parent):
    def printData(self):    # method override
        print(&#39;Child2에서 재정의&#39;)        
        print(&#39;오버라이드는 부모의 메소드를 자식이 재정의&#39;)

    def abc(self):
        print(&#39;Child2 고유 메소드&#39;)


c1 = Child1()
c1.printData()

print()

c2 = Child2()
c2.printData()

print(&#39;다형성 -----&#39;)
par = Parent()
par = c1
par.printData()
print()
par = c2
par.printData()
par.abc()

print()
plist =[c1,c2]
for i in plist:
    i.printData()
</code></pre><blockquote>
<p>다중 상속 : 순서가 중요</p>
</blockquote>
<pre><code>class Tiger:
    data = &#39;호랑이 세상&#39;

    def cry(self):
        print(&#39;호랑이는 어흥&#39;)

    def eat(self):
        print(&#39;맹수는 고기를 좋아함.&#39;)

class Lion:
    def cry(self):
        print(&#39;사자는 으르렁&#39;)

    def hobby(self):
        print(&#39;백수의 왕은 낮잠을 즐김&#39;)

class Liger1(Tiger, Lion):  # 다중 상속
    pass

a1 = Liger1()
a1.cry()        
a1.eat()
a1.hobby()
print(a1.data)

print(&#39;----------&#39;)
class Liger2(Lion, Tiger):
    data = &#39;라이거 만세&#39;

    def hobby(self):
        print(&#39;라이거는 자바를 싫어해&#39;)
    def showData(self):
        print(self.data, &#39; &#39;, super().data)
        self.hobby()
        super().hobby()



a2 = Liger2()
a2.cry()
a2.eat()
a2.hobby() # 우선순위가 있다.
a2.showData()</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 10]]></title>
            <link>https://velog.io/@hs_0919/Python-10</link>
            <guid>https://velog.io/@hs_0919/Python-10</guid>
            <pubDate>Mon, 13 Mar 2023 04:45:26 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>클래스의 상속 : 다형성을 구사 가능</p>
</blockquote>
<ol>
<li><pre><code>class Animal: 
 def __init__(self):
     print(&#39;Animal 생성자&#39;)

 def move(self):
     print(&#39;움직이는 동물 고양이 - 단풍이&#39;)
</code></pre></li>
</ol>
<p>class Dog(Animal):  # 상속
    def <strong>init</strong>(self):   # 자식의 생성자가 있을때 부모생성자 호출 x, 자식 생성자만 호출 o 
        print(&#39;Dog 생성자&#39;) # 부모 생성자는 따로 명시 해야한다. </p>
<pre><code>def my(self):
    print(&#39;난 강아지~&#39;)</code></pre><p>dog1 = Dog()<br>dog1.move()
dog1.my()        </p>
<p>print()
class Horse(Animal):
    pass </p>
<p>horse1 = Horse()
horse1.move()</p>
<pre><code>2. </code></pre><p>class Person:
    say = &#39;난 사람&#39;
    age = &#39;29&#39;
    __kbs = &#39;공영방송&#39; # private 멤버변수 - person 클래스에서만 유효하다.</p>
<pre><code>def __init__(self, age):
    print(&#39;Person 생성자&#39;)
    self.age = age      #

def printInfo(self):
    print(&#39;나이:{}, 이야기:{}&#39;.format(self.age, self.say))

def hello(self):
    print(&#39;안녕&#39;, self.__kbs)</code></pre><p>print(Person.say, Person.age)</p>
<h1 id="personprintinfo---이렇게는-쓸-수-없다">Person.printInfo -&gt; 이렇게는 쓸 수 없다.</h1>
<p>p = Person(&#39;26&#39;) # -&gt; def <strong>init</strong>(self, age) 일로 넘어옴
p.printInfo()
p.hello()</p>
<p>print(&#39;**<em>&#39;</em>10)
&#39;&#39;&#39;
class Employee(Person):
    pass
emp= Employee(&#39;27&#39;) # 부모 생성자가 실행되어서 - age 인자가 필요함
emp.printInfo()
&#39;&#39;&#39;
class Employee(Person):
    say = &#39;일하는 동물&#39;
    subject = &#39;근로자&#39;</p>
<pre><code>def __init__(self):  
    print(&#39;Employee 생성자&#39;)

def printInfo(self):
    print(&#39;Employee의 printInfo메소드&#39;)

def empPrintInfo(self):
    print(self.say, self.age, self.subject)    
    print(self.say, super().say, super().age) # super(). -&gt;  바로 부모 생성자로 올라감
    self.printInfo() # -&gt; 현재 클래스 부터 뒤짐
    super().printInfo() # -&gt; 바로 부모 클래스로 올라가 뒤짐
    self.hello()
    # print(super().say, super().__kbs) -&gt; 에러남, super().__kbs-&gt; person 클래스에서만 유효</code></pre><p>emp= Employee() # def <strong>init</strong>(self) -&gt; 인자를 하나 더 받으면 에러가 남..
emp.printInfo()
emp.empPrintInfo()</p>
<p>print(&#39;**<em>&#39;</em>10)
class Worker(Person):
    def <strong>init</strong>(self, age):
        print(&#39;Worker 생성자&#39;)
        super().<strong>init</strong>(age)   # 부모 생성자 호출 - 바운드 메소드 콜</p>
<pre><code>def wprintInfo(self):
    self.printInfo()</code></pre><p>wor = Worker(&#39;24&#39;)
print(wor.say, wor.age)
wor.wprintInfo()</p>
<p>print(&#39;**<em>&#39;</em>10)
class Programmer(Worker):
    def <strong>init</strong>(self, age):
        print(&#39;Programmer 생성자&#39;)
        # super().<strong>init</strong>(age)    # Bound call
        Worker.<strong>init</strong>(self, age) # UnBound call</p>
<pre><code>def ProShow(self):
    self.printInfo()</code></pre><p>pr = Programmer(&#39;내년 30&#39;)
print(pr.say, pr.age)
pr.ProShow()</p>
<p>print(&#39;<del>~</del>&#39;)
print(type(3))
print(type(pr))
print(type(wor))
print(Programmer.<strong>bases</strong>, Worker.<strong>bases</strong>, Person.<strong>bases</strong>)</p>
<pre><code></code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 9]]></title>
            <link>https://velog.io/@hs_0919/Python-9</link>
            <guid>https://velog.io/@hs_0919/Python-9</guid>
            <pubDate>Mon, 13 Mar 2023 04:38:45 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>자원의 재활용 : 클래스는 다른 클래스를 불러다 사용 가능</p>
</blockquote>
<ul>
<li>클래스의 포함관계(has a)</li>
</ul>
<pre><code>class Pohamhandle:  #핸들이 필요한 어떤 클래스에서든 호출될 수 있다.
    quantity= 0  # 회전량

    def LeftTurn(self, quantity):
        self.quantity = quantity
        return &#39;좌회전&#39;

    def RightTurn(self, quantity):
        self.quantity = quantity
        return &#39;우회전&#39;

    # ...</code></pre><pre><code># 여러 자동차를 위한 여러 부품 별도의 클래스로 제작 : 생략

# 완성차 클래스 
class PohamCar:
    turnShowMessage = &#39;정지&#39;

    def __init__(self, ownerName):
        self.ownerName = ownerName
        self.handle = Pohamhandle() # 클래스의 포함

    def TurnHandle(self, q):
        if q &gt; 0 :
            self.turnShowMessage = self.handle.RightTurn(q)
        elif q &lt; 0 :
            self.turnShowMessage = self.handle.LeftTurn(q)
        elif q == 0 :
            self.turnShowMessage = &#39;직진&#39;
            self.handle.quantity= 0</code></pre><pre><code>if __name__ == &#39;__main__&#39;:
    tom = PohamCar(&#39;톰&#39;)
    tom.TurnHandle(10)
    print(tom.ownerName + &#39;의 회전량은 &#39;+ tom.turnShowMessage + str(tom.handle.quantity))

    tom = PohamCar(&#39;톰&#39;)
    tom.TurnHandle(0)
    print(tom.ownerName + &#39;의 회전량은 &#39;+ tom.turnShowMessage + str(tom.handle.quantity))
    print()
    oscar = PohamCar(&#39;오스카&#39;)
    oscar.TurnHandle(-5)
    print(oscar.ownerName + &#39;의 회전량은 &#39;+ oscar.turnShowMessage + str(oscar.handle.quantity))</code></pre><pre><code># 내장고에 음식 담기 - 클래스의 포함관계로 구현


class Fridge:
    isOpened = False
    foods = []

    def open(self):
        self.isOpened =True
        print(&#39;냉장고 문 열기&#39;)

    def put(self, thing):
        if self.isOpened:
            self.foods.append(thing) # 포함관계
            print(&#39;냉장고 안에 음식을 저장함.&#39;)
            self.food_list()
        else:
            print(&#39;냉장고 문이 닫쳐 있어 음식을 저장할 수 없다.&#39;)

    def close(self):
        self.isOpened = False
        print(&quot;냉장고 문 닫기&quot;)



    def food_list(self):
        for f in self.foods:
            print(&#39;-&#39;, f.name, f.expiry_date)
        print()

class FoodData:
    def __init__(self, name, expiry_date):
        self.name = name
        self.expiry_date = expiry_date

if __name__ == &#39;__main__&#39;:
    f = Fridge()

    apple = FoodData(&#39;사과&#39;, &#39;2022-10-25&#39;)
    f.put(apple)
    f.open()
    f.put(apple)
    f.close()
    print()
    minfe=FoodData(&#39;민철&#39;,&#39;2088-11-11&#39;)
    f.open()
    f.put(minfe)
    f.close()
</code></pre><blockquote>
<p>클래스의 포함관계 : 로또번호 출력기</p>
</blockquote>
<pre><code>import random

class LottoBall:
    def __init__(self, num):
        self.num = num

class Lottomachine:
    def __init__(self):
        self.ballList =[]
        for i in range(1, 46):
            self.ballList.append(LottoBall(i)) #포함 관계

    def selectBalls(self):
        # 볼 섞기 전 출력하기
        for a in range(45):
            print(self.ballList[a].num, end=&#39; &#39;)
        random.shuffle(self.ballList)   # 랜덤하게 공을 섞기 
        print()
        for a in range(45):
            print(self.ballList[a].num, end=&#39; &#39;)
        return self.ballList[0:6]


print()
class LottoUi:
    def __init__(self):
        self.machine = Lottomachine() # 포함

    def playLotto(self):
        input(&#39;로또를 시작 하려면 엔터키를 누르세요!&#39;)
        selectedBalls = self.machine.selectBalls()
        print(&#39;당첨번호&#39;)
        for ball in selectedBalls:
            print(&#39;%d &#39;%ball.num, end=&#39; &#39;)

if __name__ == &#39;__main__&#39;:
    #lo = LottoUi()
    #lo.playLotto()
    LottoUi().playLotto()</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 8]]></title>
            <link>https://velog.io/@hs_0919/Python-8</link>
            <guid>https://velog.io/@hs_0919/Python-8</guid>
            <pubDate>Mon, 13 Mar 2023 04:24:45 GMT</pubDate>
            <description><![CDATA[<ol>
<li>예제<pre><code># class : 새로운 타입을 생성
print(&#39;가수 관련 클래스&#39;)
</code></pre></li>
</ol>
<p>class SingerType():
    title_song = &#39;화이팅 코리아&#39;</p>
<pre><code>def sing(self):
    msg = &#39;노래는 &#39;
    print(msg, self.title_song+ &#39;la la la&#39;)</code></pre><pre><code>
2. import</code></pre><h1 id="가수-한-명을-탄생">가수 한 명을 탄생!</h1>
<p>from pack02.class4 import SingerType</p>
<p>def process():</p>
<pre><code>youngwoung = SingerType()
print(&#39;영웅의 타이틀 송 : &#39;, youngwoung.title_song)
youngwoung.sing()</code></pre><p>def process2():
    bts = SingerType()
    bts.sing()
    bts.title_song = &#39;yet to come&#39;
    bts.sing()
    bts.co = &#39;HIVE&#39;
    print(&#39;소속사:&#39;, bts.co)
    print()
    blackPink = SingerType()
    blackPink.title_song=&#39;shut down&#39;
    blackPink.sing()
    blackPink.co = &#39;YG&#39;
    print(&#39;소속사:&#39;, blackPink.co)</p>
<h1 id="process">process()</h1>
<p>if <strong>name</strong> == &#39;<strong>main</strong>&#39;:
    process()
    print(&#39;------&#39;)
    process2()</p>
<pre><code>
3. 예제 - 카페 자판기 만들기</code></pre><p>class CoinIn:</p>
<pre><code>def insert(self):
    self.coin=int(input(&#39;동전을 넣어주세요&#39;))
    return self.coin</code></pre><p>class Machine:</p>
<pre><code>def showData(self):

    print(&#39;커피는 한잔에 200원 입니다&#39;)
    self.coin=CoinIn().insert()
    self.count=int(input(&#39;몇잔을 원하세요?&#39;))

    if 200*self.count &gt; self.coin:
        print(&#39;요금이 부족합니다&#39;)
    elif 200*self.count &lt;= self.coin:
        refund=self.coin-(200*self.count)
        print(&#39;커피 %d잔과&#39;%self.count,&#39;잔돈 %d원&#39;%refund)</code></pre><p>if <strong>name</strong>==&#39;<strong>main</strong>&#39;:
    Machine().showData()</p>
<pre><code>- 다른 코드</code></pre><p>class CoinIn:
    def calc(self, cupCount):
        re = &quot;&quot;</p>
<pre><code>    if self.coin &lt; 200:
        re = &quot;요금이 부족하네요&quot;
    elif cupCount * 200 &gt; self.coin:
        re = &quot;요금이 부족하네요&quot;
    else:
        self.change = self.coin - (200 * cupCount)  # 잔돈 계산
        re = &quot;커피 {}잔과 잔돈 {}원&quot;.format(cupCount, self.change)

    return re</code></pre><p>class Machine():
    cupCount = 1  # 현재 코드에서는 의미 없음</p>
<pre><code>def __init__(self):
    self.coinIn = CoinIn()  # 포함

def showData(self):
    self.coinIn.coin = int(input(&quot;동전을 입력하세요 :&quot;))
    self.cupCount = int(input(&quot;몇 잔을 원하세요 :&quot;))

    print(self.coinIn.calc(self.cupCount))</code></pre><p>if <strong>name</strong> == &#39;<strong>main</strong>&#39;:
    Machine().showData()
```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 7]]></title>
            <link>https://velog.io/@hs_0919/Python-7</link>
            <guid>https://velog.io/@hs_0919/Python-7</guid>
            <pubDate>Mon, 13 Mar 2023 04:07:55 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>class : 새로운 타입을 생성. 객체 지향적(중심적)인 프로그래밍</p>
</blockquote>
<ul>
<li>형식 class 클래스명(): 멤버(필드, 메소드) ~</li>
<li>생성자, 소멸자가 있다, 접근지정자가 없다. </li>
<li>다중상속 가능, interface가 없다.</li>
</ul>
<ol>
<li><pre><code>print(&#39;뭔가를 하다가 모듈의 멤버인 클래스를 선언하기&#39;)
class TestClass:    # prototype , 원형클래스 객체 생성. 고유의 이름 공간을 확보
 aa =1 # 멤버변수(멤버필드), public

 def __init__(self): # 생성자
     print(&#39;생성자&#39;)

 def __del__(self):
     print(&#39;소멸자&#39;)

 def printMessage(self): # method
     name= &#39;한국인&#39;  # 지역변수
     print(name)
     print(self.aa)
</code></pre></li>
</ol>
<p>print(TestClass, id(TestClass))
print(TestClass.aa)</p>
<p>test = TestClass()  # 생성자를 호출한 후 TestClass type의 객체 생성
print(test.aa)  # 멤버필드 호출</p>
<pre><code></code></pre><h1 id="메소드-호출">메소드 호출</h1>
<h1 id="testclassprintmessage--에러뜸">TestClass.printMessage() =&gt; 에러뜸</h1>
<p>test.printMessage()
TestClass.printMessage(test) # UnBound method call
print()
test.printMessage()  # Bound method call</p>
<pre><code>
2. </code></pre><p>class Car: 
    handle = 0  # Car type의 객체에서 참조 가능 멤버 필드
    speed = 0</p>
<pre><code>def __init__(self, name, speed):
    self.name = name
    self.speed = speed

def showData(self): # Car type의 객체에서 참조 가능 멤버 메소드
    km = &#39;킬로미터&#39;
    msg = &#39;속도:&#39; + str(self.speed) + km + &#39;, 핸들은 &#39; + str(self.handle)
    return msg</code></pre><p>print(id(Car))
print(Car.handle)
print(Car.speed)
print(&#39;-------&#39;)
car1 = Car(&#39;tom&#39;, 10)   # 생성자 호출 후 객체 생성-&gt; <strong>init</strong> 으로
print(car1.handle, car1.name, car1.speed)
car1.color = &#39;보라해&#39;
print(&#39;car1 color : %s&#39;%car1.color)</p>
<p>print(&#39;-------&#39;)
car2=Car(&#39;james&#39;, 20)
print(car2.handle, car2.name, car2.speed)</p>
<h1 id="printcar2-color--scar2color---err--car-object-has-no-attribute-color">print(&#39;car2 color : %s&#39;%car2.color) #  err -&gt;&#39;Car&#39; object has no attribute &#39;color&#39;</h1>
<p>print(&#39;주소 : &#39;, id(Car), id(car1), id(car2))</p>
<p>print(car1.showData())
print(car2.showData())  # 바운드 메소드 콜
print(Car.showData(car2))   # 언바운드 메소드 콜
print(&quot;------&quot;)
car2.speed = 100
Car.handle = 1
car1.handle = 2
print(&#39;car1 : &#39;, car1.showData())  # 10
print(&#39;car2 : &#39;, car2.showData())  # 100
&#39;&#39;&#39;
Car의 설계도가 static에 있고
car1=Car(&#39;tom&#39;,10) 하면
car1이라는 변수가 stack 영역에 있는데 
car1이 heap 영역에 있는 Car(&#39;tom&#39;,10) 의 주소를 참조
&#39;&#39;&#39;</p>
<pre><code>3. class의 이해
</code></pre><p>kor = 100   # 전역변수</p>
<p>def abc():  # 함수
    a = 10  # 지역 변수
    print(&#39;함수&#39;)</p>
<p>class MyClass:    # 클래스
    kor =90       # 멤버변수</p>
<pre><code>&quot;&quot;&quot;
def __init__(self): 되도록 안쓰는것이 좋음
    pass
&quot;&quot;&quot;
def abc(self):
    print(&#39;메소드&#39;)

def show(self):
    #kor = 80    # 지역변수
    print(self.kor)
    print(kor)  # 지역변수를 찾다가 없으면 전역변수 참조
    self.abc()  # 메소드 콜
    abc()       # 함수 콜</code></pre><p>my = MyClass()
my.show()
```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 6]]></title>
            <link>https://velog.io/@hs_0919/Python-6</link>
            <guid>https://velog.io/@hs_0919/Python-6</guid>
            <pubDate>Fri, 10 Mar 2023 00:41:38 GMT</pubDate>
            <description><![CDATA[<h2 id="반복문-for">반복문 for</h2>
<h3 id="for-변수-in-집합형-자료">for 변수 in 집합형 자료:...</h3>
<p>1.</p>
<pre><code>#for i in [1,2,3,4,5]: # list
#for i in (1,2,3,4,5): # 튜플
for i in {1,2,3,4,5}: # set
    print(i, end=&#39; &#39;)    
print()
soft ={&#39;java&#39;:&#39;웹영언어&#39;, &#39;python&#39;:&#39;만능언어&#39;, &#39;MariaDB&#39;:&#39;데이터 처리&#39;}
print(soft.items()) #dict_items([(&#39;java&#39;, &#39;웹영언어&#39;), (&#39;python&#39;, &#39;만능언어&#39;), (&#39;MariaDB&#39;, &#39;데이터 처리&#39;)])

for i in soft.items():
    #print(i) # 튜플만 보임
    print(i[0] + &#39;^^;&#39; + i[1])

print()
for k in soft.keys():
    print(k, end=&#39; &#39;)

print()
for k in soft.values():
    print(k, end=&#39; &#39;)</code></pre><ol start="2">
<li><pre><code>print()
li = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;]
for idx, data in enumerate(li): # enumerate() - index를 반환함
 print(idx, data)
</code></pre></li>
</ol>
<p>print(&#39;\n평균, 분산, 표준편차 구하기&#39;) # 평균이란... 검색해보기
jum = [1,3,5,7,9]
print(jum)</p>
<p>tot =0
for i in jum:
    tot +=i</p>
<p>avg =tot/len(jum)
print(&#39;mean : &#39;, avg)</p>
<p>tot= 0
for i in jum:
    tot += (i - avg) ** 2  # (i - avg)-편차</p>
<p>var = tot/len(jum)
print(&#39;var : &#39;, var) # 분산은 편차 제곱합의 평균
import math
print(&#39;std : &#39;, math.sqrt(var)) # 표준편차 # = print(&#39;std : &#39;, var ** 0.5)</p>
<pre><code>
3. 다량의 문자열 데이터 중 단어 수 출력</code></pre><p>import re
ss = &#39;&#39;&#39;
5일 코로나19 신규확진자 수가 3만4739명을 기록했다. 전일보다 1420명 줄었다. 
위중증 환자와 사망자 등 방역 관련 모든 지표가 안정세다. 
이제 방역 관건은 코로나19 자체보다 독감이라는 말이 의료계에서 나온다.
3년만에 독감 유행이 예고됐으며 독감과 코로나19가 동시 유행할 경우 환자 중증도가 크게 올라갈 우려가 있어서다.
게다가 올해 유행할 독감은 독감 바이러스 중에서도 가장 강한 &#39;A형 H3N2&#39;다. 
적극적 독감백신 접종이 필요하다는 것이 방역당국과 의료계 공통된 의견이다.
중앙방역대책본부는 이날 0시 기준 신규확진자 수가 3만4739명을 기록했다고 밝혔다. 
이 가운데 해외 유입사례 69명을 제외한 국내 확진자 수는3만4670명이었다. 
수도권에서 전체 국내 확진의 56.5% 비중인 1만9587명이 확진됐다. 
재원중 위중증 환자는 330명으로 전일대비 20명 감소했다. 
사망자는 16명으로 전일보다 3명 줄었다. 누적 사망자는 2만8544명(치명률 0.11%)이다.
&#39;&#39;&#39;
print(ss)
print()
ss2 = re.sub(r&#39;[^가-힣\s]&#39;, &#39;&#39;, ss)
print(ss2)
ss3 = ss2.split(&#39; &#39;)
print(ss3)</p>
<p>cou={} # 단어의 발생 횟수를 dict 로 저장
for i in ss3:
    if i in cou:
        cou[i]+=1
    else:
        cou[i]=1
print(cou)</p>
<pre><code>
4. </code></pre><p>for test_str in [&#39;111-1234&#39;, &#39;일이삼-사오육칠&#39;, &#39;222-1234&#39;]:
    if re.match(r&#39;^\d{3,4}-\d{4}$&#39;,test_str):
        print(test_str, &#39;전화번호 맞아요&#39;)
    else:
        print(test_str, &#39;음...&#39;)</p>
<pre><code>5.</code></pre><p>print(&#39;사전형 사료로 과일값 출력&#39;)
price ={&#39;사과&#39;:2000, &#39;감&#39;:500, &#39;배&#39;:1000}
guest ={&#39;사과&#39;:2, &#39;감&#39;:3}
bill = sum(price[f] * guest[f] for f in guest)
print(&#39;고갱님이 구매한 과일 총액 : {}원&#39;.format(bill))</p>
<h1 id="고갱님이-구매한-과일-총액--5500원">고갱님이 구매한 과일 총액 : 5500원</h1>
<pre><code>6.</code></pre><p>temp =[1,2,3]
for i in temp :
    print(i, end=&#39; &#39;)
print()
print([i for i in temp])
print({i for i in temp})</p>
<p>temp2 = list()
for i in temp:
    temp2.append(i + 10)
print(temp2)
temp2 =[i+10 for i in temp]
print(temp2)</p>
<p>print()
datas =[1,2,&#39;a&#39;, True, 3]
li =[i * i for i in datas if type(i) == int]
print(li)</p>
<p>print()
datas = {1,1,2,2,2,3}
se = {i*i for i in datas} # set type 이라 중복을 제거
print(se)</p>
<p>print()
id_name = {1:&#39;tom&#39;, 2:&#39;james&#39;}
name_id ={value:key for key, value in id_name.items()}
print(name_id)</p>
<pre><code>
### for + range

1. </code></pre><p>print(list(range(1,6,1))) # 1부터 6사이에 숫자를 표시하고, 그 숫자들의 차이가 1이다.
print(set(range(1,6)))
print(tuple(range(1,6)))
print(list(range(1,11,2))) # 1부터 11사이에 숫자를 표시하고, 그 숫자들의 차이가 2이다.</p>
<p>print(list(range(6)))
print(list(range(0,6,1)))
print(list(range(-10, -100, -20)))</p>
<pre><code>2. _ : 반복만 해줘, 참조X</code></pre><p>for _ in range(6): # _ : 반복만 해줘, 참조X
    print(&#39;hi&#39;, end=&#39; &#39;)
    # pass</p>
<pre><code>3. 구구단 2단 만들때</code></pre><p>for i in range(1,10):
    print(&#39;{0}<em>{1}={2}&#39;.format(2, i, 2</em>i), end=&#39; &#39;)</p>
<pre><code>4. 예제1</code></pre><h1 id="문1-29-단-까지-출력">문1) 2~9 단 까지 출력</h1>
<p>for n in range(2,10):
    print(&#39;---{}단---&#39;.format(n))
    for i in range(1,10):
        print(&#39;{}<em>{}={}&#39;.format(n, i, n</em>i))
    print()</p>
<pre><code>5. 예제2</code></pre><h1 id="문2-1100-사이의-3의-배수이면서-5의-배수의-합-출력">문2) 1~100 사이의 3의 배수이면서 5의 배수의 합 출력</h1>
<p>a=0;
for n in range(1,101):
    if n % 3 == 0 and n % 5 ==0:
        a += n
print(&#39;합은&#39;, a) # 합은 315</p>
<pre><code>6. 예제3</code></pre><h1 id="문3-주사위를-두번-던져서-나온-숫자들의-합이-4의-배수가-되는-경우만-두-수-출력">문3) 주사위를 두번 던져서 나온 숫자들의 합이 4의 배수가 되는 경우만 두 수 출력</h1>
<h1 id="출력-예-1-3">출력 예) 1 3</h1>
<h1 id="2-2">2 2</h1>
<h1 id="">...</h1>
<p>for i in range(1,7):
    for j in range(1,7):
        su = i + j 
        if su % 4 == 0:
            print(i, j)
print()</p>
<pre><code>7. </code></pre><h1 id="n-gram--문자열에서-n개의-연속된-요소를-추출하는-방법">n-gram : 문자열에서 N개의 연속된 요소를 추출하는 방법</h1>
<p>text=&#39;hello&#39;</p>
<p>for i in range(len(text)-1):
    print(text[i:i+2])</p>
<p>&#39;&#39;&#39;
he
el
ll
lo
&#39;&#39;&#39;
```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 5 ]]></title>
            <link>https://velog.io/@hs_0919/Python-5</link>
            <guid>https://velog.io/@hs_0919/Python-5</guid>
            <pubDate>Fri, 10 Mar 2023 00:23:10 GMT</pubDate>
            <description><![CDATA[<h2 id="반복문-continue-break">반복문 continue, break</h2>
<ol>
<li><pre><code>a=0
while a &lt; 10:
 a += 1
 if a ==3:continue
 if a ==5:break
 print(a)
else: # while문이 정상적으로 수행되었는지 확인하기 위해 쓸 수 있다.
 print(&#39;while문 정상 수행&#39;)
print(&#39;while 수행 후 %d&#39;%a)</code></pre></li>
<li><p>난수 발생</p>
<pre><code># 난수 발생 
import random
random.seed(2) # 랜덤한 값을 고정시키고 싶을때 사용, 
num = random.randint(1, 10)
#print(num)
# while True: #무한루프
#     print(&#39;1~`0 사이의 컴이 가진 예상 숫자 입력:&#39;)
#     guess = int(input())
#     if guess == num:
#         print(&#39;성공&#39;*10)
#         break
#     elif guess &lt; num:
#         print(&#39;더 큰 수 입력&#39;)
#     elif guess &gt; num:
#         print(&#39;더 작은 수 입력&#39;)</code></pre></li>
<li><p>의사 난수(pseudo random)</p>
<pre><code>friend = [&#39;tom&#39;, &#39;john&#39;, &#39;oscar&#39;]
print(friend)
print(random.choice(friend)) # 하나만 랜덤하게 선택
print(random.sample(friend, 2)) # 표본 랜덤하게 2개만 뽑기
random.shuffle(friend)
print(friend)</code></pre></li>
</ol>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 4 ]]></title>
            <link>https://velog.io/@hs_0919/Python-4</link>
            <guid>https://velog.io/@hs_0919/Python-4</guid>
            <pubDate>Fri, 10 Mar 2023 00:20:06 GMT</pubDate>
            <description><![CDATA[<h2 id="반복문-while">반복문 while</h2>
<h3 id="while-조건---참이면-수행">while 조건 : ~ 참이면 수행</h3>
<ol>
<li><pre><code>a =1
while a &lt;= 5:
 print(a, end=&#39; &#39;)
 a += 1
</code></pre></li>
</ol>
<p>print(&#39;while 수행 후 %d&#39;%a)</p>
<h1 id="1-2-3-4-5-while-수행-후-6">1 2 3 4 5 while 수행 후 6</h1>
<p>print()
i=1
while i&lt;=3:
    j=1
    while j&lt;4:
        print(&#39;i:&#39;+str(i) + &#39;, j:&#39; +str(j))
        j =j+1
    i += 1</p>
<pre><code>2. </code></pre><p>print(&#39;1~100 사이의 정수 중 3의 배수의 합 출력&#39;)
i=1; hap=0
while i&lt;100:
    if i % 3 == 0:
        # print(i, end=&#39; &#39;)
        hap += i
    i += 1
    # print(i, end=&#39; &#39;)</p>
<p>print(&#39;합은 {}&#39;.format(hap)) # 합은 1683</p>
<pre><code>3.</code></pre><p>colors=[&#39;r&#39;, &#39;g&#39;, &#39;b&#39;]
print(colors[0])
a=0
while a&lt;len(colors):
    print(colors[a], end=&#39; &#39;)
    a +=1</p>
<p>print()</p>
<p>while colors:
    print(colors.pop(0), end=&#39; &#39;)
    # print(len(colors))</p>
<p>&#39;&#39;&#39;
r
r g b 
r g b 
&#39;&#39;&#39;</p>
<pre><code>4.</code></pre><p>i=1
while i &lt;= 10:
    j=1
    re=&#39;&#39;
    while j&lt;=i:
        re =re + &#39;<em>&#39;
        j += 1
    print(re)
    i += 1
&quot;&quot;&quot;
*
*</em></p>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
<p>&quot;&quot;&quot;</p>
<pre><code>5. 폭탄 스위치 </code></pre><p>import time
#time.sleep(3)
sw =input(&#39;폭탄 스위치를 누를까요?[y/n]&#39;)
if sw == &#39;Y&#39; or sw == &#39;y&#39;:
    count =5
    while 1 &lt;= count:
        print(&#39;%d 초 남았습니다.&#39;%count)
        time.sleep(1)
        count -= 1
    print(&#39;폭발합니다.&#39;)
elif sw == &#39;N&#39; or sw == &#39;n&#39;:
    print(&#39;작업 취소&#39;)
else:
    print(&#39;y 또는 n을 누르세요&#39;)</p>
<p>print(&#39;end&#39;)</p>
<pre><code>6. 예제1</code></pre><h1 id="문1-1--100-사이의-숫자-중-3의-배수이나-2의-배수가-아닌-수를-출력하고-합을-출력">문1) 1 ~ 100 사이의 숫자 중 3의 배수이나 2의 배수가 아닌 수를 출력하고, 합을 출력</h1>
<p>i=0; hap=0
while i&lt;=100:
    i += 1
    if i % 3 == 0 and not i % 2 == 0: # i % 2 != 0
        print(i, end=&#39; &#39;)
        hap += i</p>
<p>print(&#39;합은 {}&#39;.format(hap))</p>
<h1 id="3-9-15-21-27-33-39-45-51-57-63-69-75-81-87-93-99-합은-867">3 9 15 21 27 33 39 45 51 57 63 69 75 81 87 93 99 합은 867</h1>
<pre><code>
7. 예제2</code></pre><p>#문2) 2 ~ 5 까지의 구구단 출력
i=1
while i &lt; 5:
    i += 1
    j = 1
    while j &lt;10:
        print(i, &#39;X&#39;, j, &#39;=&#39;, i*j)
        j += 1</p>
<pre><code>8. 예제3</code></pre><p>#문3) -1, 3, -5, 7, -9, 11 ~ 99 까지의 모두에 대한 합을 출력
i=1
cnt=1
tot=0</p>
<p>while i&lt;100:
    if cnt % 2 ==0: # 짝수 위치 숫자 처리
        tot += i
        print(i, end =&#39; &#39;)
    else:  # 홀수 위치 숫자 처리
        k = i * -1 # 부호 변경
        tot += k
        print(k, end=&#39; &#39;)
    cnt += 1
    i += 2 # 증가치 2
print(&#39;\ntot : &#39;, tot)</p>
<h1 id="tot---50">tot :  50</h1>
<pre><code>
9. 예제4</code></pre><h1 id="문4-1--1000-사이의-소수1보다-크며-1과-자신의-수-이외에는-나눌-수-없는-수와-그-갯수를-출력">문4) 1 ~ 1000 사이의 소수(1보다 크며 1과 자신의 수 이외에는 나눌 수 없는 수)와 그 갯수를 출력</h1>
<p>aa=2
count=0</p>
<p>while aa&lt;=1000:
    imsi =False
    bb=2;</p>
<pre><code>while bb&lt;= aa -1:
    if aa % bb == 0:
        imsi = True
    bb += 1

if imsi == False:
    print(aa, end=&#39; &#39;)
    count += 1
aa += 1</code></pre><p>print(&#39;\ncount : &#39;, count)</p>
<h1 id="count---168">count :  168</h1>
<pre><code>
### while / if 연습문제

1. </code></pre><h1 id="문1-1--100-사이의-숫자-중-3의-배수이나-2의-배수가-아닌-수를-출력하고-합을-출력-1">문1) 1 ~ 100 사이의 숫자 중 3의 배수이나 2의 배수가 아닌 수를 출력하고, 합을 출력</h1>
<p>i = hap = 0</p>
<p>while i &lt;= 100:
    i += 1
    if i % 3 == 0 and i % 2 != 0:
        print(i, end = &#39; &#39;)
        hap += i</p>
<p>print(&#39;합은 {}&#39;.format(hap))</p>
<h1 id="3-9-15-21-27-33-39-45-51-57-63-69-75-81-87-93-99-합은-867-1">3 9 15 21 27 33 39 45 51 57 63 69 75 81 87 93 99 합은 867</h1>
<pre><code>2. </code></pre><h1 id="문2-2--5-까지의-구구단-출력">문2) 2 ~ 5 까지의 구구단 출력</h1>
<p>print()
i = 2
while i &lt; 6:
    j = 1
    while j &lt; 10:
        print(i, &#39;*&#39; , j, &#39;=&#39;, i * j, end = &#39; &#39;)
        j += 1
    print()
    i += 1</p>
<pre><code></code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 3 ]]></title>
            <link>https://velog.io/@hs_0919/Python-3</link>
            <guid>https://velog.io/@hs_0919/Python-3</guid>
            <pubDate>Thu, 09 Mar 2023 04:20:22 GMT</pubDate>
            <description><![CDATA[<ul>
<li>정규 표현식 : 다량의 데이터에서 원하는 데이터만 선택해서 처리할 때 효과적<pre><code>import re
</code></pre></li>
</ul>
<p>ss =&quot;12_1234 abc가나다abc_nbc_ABC_1234555_6한국Python is fun.&quot;
print(ss)
print(re.findall(r&#39;123&#39;, ss)) # r을 쓰는게 좋다.
print(re.findall(r&#39;가나다&#39;, ss))
print(re.findall(r&#39;1&#39;, ss))
print(re.findall(r&#39;[1-2]&#39;, ss))
print(re.findall(r&#39;[0-9]&#39;, ss)) #정규표현식에선 띄어쓰기 하면안됨.
print(re.findall(r&#39;[0-9]+&#39;, ss))
print(re.findall(r&#39;[0-9]{2}&#39;, ss)) # {} - 횟수 반복(?)
print(re.findall(r&#39;[0-9]{2,3}&#39;, ss))#2개짜리~ 3개짜리
print(re.findall(r&#39;[a-z]+&#39;, ss))
print(re.findall(r&#39;[A-Za-z]+&#39;, ss)) # + - 한개 이상, * - 0개 이상, ? - 0 또는 1
print(re.findall(r&#39;[가-힣]+&#39;, ss))
print(re.findall(r&#39;[^가-힣]+&#39;, ss)) # ^ - 부정 
print(re.findall(r&#39;12|34&#39;, ss))
print(re.findall(r&#39;.bc&#39;, ss)) # . - 아무거나
print(re.findall(r&#39;...&#39;, ss)) # ... - 세글자 아무거나
print(re.findall(r&#39;[^1]+&#39;, ss)) # 부정
print(re.findall(r&#39;^1+&#39;, ss)) # 첫글자 1
print(re.findall(r&#39;fun.$&#39;, ss)) # $ 끝나는거 </p>
<p>print(re.findall(r&#39;\d&#39;, ss)) # 숫자만 나옴
print(re.findall(r&#39;\d+&#39;, ss))# 그룹이 된다.
print(re.findall(r&#39;\s&#39;, ss))
print(re.findall(r&#39;\S&#39;, ss))
print(re.findall(r&#39;\d{1,3}&#39;, ss)) # 1~3 까지</p>
<p>print()
p=re.compile(&#39;the&#39;, re.IGNORECASE)
print(p)
print(p.findall(&#39;The do the dog&#39;))
print()</p>
<p>ss=&#39;&#39;&#39;My name is tom.
I am happy&#39;&#39;&#39;
print(ss)
p=re.compile(&#39;^.+&#39;,re.MULTILINE)
print(p.findall(ss))</p>
<h1 id="my-name-is-tom-i-am-happy">[&#39;My name is tom.&#39;, &#39;I am happy&#39;]</h1>
<pre><code>
#### 조건 판단문 if
#### if 조건 : 실행문 elif 조건 ~ else : ~</code></pre><p>var =1
if var &gt;= 3:        #java : {}, py : 들여쓰기
    print(&#39;크구나&#39;)
    print(&#39;참일 때&#39;)
    # pass  아무것도 수행 하지 않음.
else:
    print(&#39;거짓일 때&#39;)    </p>
<p>print(&#39;end1&#39;)</p>
<p>print()
money= 1000
age= 35</p>
<p>if money &gt;= 500:
    item =&#39;사과&#39;
    if age &lt;= 30:
        msg =&#39;청춘이다&#39;
    else:
        msg =&#39;라떼는 말야...&#39;
else:
    item =&#39;포도&#39;
    if age &gt;= 30:
        msg =&#39;성인이다&#39;
    else:
        msg =&#39;잼민이다&#39;
print(item, msg)</p>
<pre><code></code></pre><p>jumsu = 85
if jumsu &gt;= 90:
    print(&#39;우수&#39;)
else:
    if jumsu &gt;= 70:
        print(&#39;보통&#39;)
    else:
        print(&#39;망&#39;)</p>
<p>print()
if jumsu &gt;= 90:
    print(&#39;우수&#39;)
elif jumsu &gt;= 70:
    print(&#39;보통&#39;)
else:
    print(&#39;망&#39;)</p>
<p>print()
print(int(&#39;5&#39;)+5) # 형변환 : int(), str()
print(str(5)+&#39;5&#39;)</p>
<p>#jum = int(input(&#39;점수 입력:&#39;))
jum =80</p>
<h1 id="printjum-typejum">print(jum, type(jum))</h1>
<p>#if jum &gt;= 90 and jum &lt;=100:</p>
<p>if 90 &lt;= jum &lt;= 100:
    grade=&#39;우수학생&#39;
elif 70 &lt;= jum &lt;90:
    grade =&#39;보통학생&#39;
else:
    grade =&#39;저조학생&#39;
print(grade)</p>
<p>print()
names =[&#39;홍길동&#39;, &#39;신기해&#39;, &#39;이기자&#39;]
if &#39;홍길동&#39; in names: # not in - 부정, 부정문 좋지 않음 -속도가 떨어짐
    print(&#39;친구 이름&#39;)
else:
    print(&#39;누구니?&#39;)</p>
<p>print()</p>
<pre><code></code></pre><p>jumsu = 85
if jumsu &gt;= 90:
    print(&#39;우수&#39;)
else:
    if jumsu &gt;= 70:
        print(&#39;보통&#39;)
    else:
        print(&#39;망&#39;)</p>
<p>print()
if jumsu &gt;= 90:
    print(&#39;우수&#39;)
elif jumsu &gt;= 70:
    print(&#39;보통&#39;)
else:
    print(&#39;망&#39;)</p>
<p>print()
print(int(&#39;5&#39;)+5) # 형변환 : int(), str()
print(str(5)+&#39;5&#39;)</p>
<p>#jum = int(input(&#39;점수 입력:&#39;))
jum =80</p>
<h1 id="printjum-typejum-1">print(jum, type(jum))</h1>
<p>#if jum &gt;= 90 and jum &lt;=100:</p>
<p>if 90 &lt;= jum &lt;= 100:
    grade=&#39;우수학생&#39;
elif 70 &lt;= jum &lt;90:
    grade =&#39;보통학생&#39;
else:
    grade =&#39;저조학생&#39;
print(grade)</p>
<p>print()
print(int(&#39;5&#39;)+5) # 형변환 : int(), str()
print(str(5)+&#39;5&#39;)</p>
<p>#jum = int(input(&#39;점수 입력:&#39;))
jum =80</p>
<h1 id="printjum-typejum-2">print(jum, type(jum))</h1>
<p>#if jum &gt;= 90 and jum &lt;=100:</p>
<p>if 90 &lt;= jum &lt;= 100:
    grade=&#39;우수학생&#39;
elif 70 &lt;= jum &lt;90:
    grade =&#39;보통학생&#39;
else:
    grade =&#39;저조학생&#39;
print(grade)</p>
<p>print()
names =[&#39;홍길동&#39;, &#39;신기해&#39;, &#39;이기자&#39;]
if &#39;홍길동&#39; in names: # not in - 부정, 부정문 좋지 않음 -속도가 떨어짐
    print(&#39;친구 이름&#39;)
else:
    print(&#39;누구니?&#39;)</p>
<p>print()
a = &#39;kbs&#39;
b = 9 if a == &#39;kbs&#39; else 11 # 이런식으로 많이 사용한다.
print(b)</p>
<p>a = 11
b = &#39;mbc&#39; if a == 9 else &#39;kbs&#39;
print(b)</p>
<p>print()
a = 3 
if a &lt;5:
    print(0)
elif a&lt;10:
    print(1)
else:
    print(2)</p>
<p>print(0 if a &lt; 5 else 1 if a &lt;10 else 2)</p>
<p>print(a * 2 if a &gt; 5 else a + 2 )</p>
<p>print((a+2, a<em>2)[a &gt;5]) # [a &gt;5] -&gt; false 라서 a+2 실행, true면 a</em>2 실행 </p>
<p>```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python - 2 ]]></title>
            <link>https://velog.io/@hs_0919/Python-2</link>
            <guid>https://velog.io/@hs_0919/Python-2</guid>
            <pubDate>Thu, 09 Mar 2023 04:03:25 GMT</pubDate>
            <description><![CDATA[<ul>
<li>집합 자료형 : str, list, tuple, set, dict</li>
</ul>
<ol>
<li>문자열 : str - 순서 o: 인덱싱(하나의 값만 참조), 슬라이싱(여러값 참조)이 가능 , 수정 x <pre><code>s=&quot;sequence&quot;
print(s, type(s), len(s))
print(s.count(&#39;e&#39;))
print(s.find(&#39;e&#39;), &#39;&#39;, s.find(&#39;e&#39;,3), s.rfind(&#39;e&#39;))# rfind- 뒤에서부터</code></pre><pre><code># 수정 불가
ss=&#39;mbc&#39;
print(ss, id(ss))
ss=&#39;abc&#39;
print(ss, id(ss))</code></pre></li>
<li>인덱싱,  슬라이싱  대상[start:stop:step]<pre><code>s=&#39;sequence&#39;
print(s[0], s[3]) # s[8] err남
print(s[-1], s[-3])
</code></pre></li>
</ol>
<p>print(s[0:3], s[3:], s[:3], s[:], s[1:5:2], s[::2]) 
#0 이상 3 미만, 3자리 이후로, 3자리 까지, 몽땅 다, 1이상 5미만 증가치2, 모든 글자에서 2번째는 빼고 
print(s[-4:-1], s[-3:])
print(&#39;fre&#39; + s[2:]) # 일부의 값만 참조
print()</p>
<pre><code></code></pre><p>s2=&#39;kbs mbc&#39;
s2=&#39; &#39; + s2[:4] + &#39;sbs &#39; + s2[4:] + &#39; &#39;
print(s2, len(s2))
print(s2.strip()) # strip() -&gt; 인자를 전달하지 않으면 String에서 공백을 제거한다.
                  # lstrip() -&gt; 인자로 전달된 문자를 왼쪽에서부터 제거한다.
                  # rstrip() -&gt; 인자로 전달된 문자를 오른쪽에서부터 제거한다.</p>
<p>s3=s2.split(sep=&#39; &#39;) #split() -&gt; 문자열을 일정한 규칙으로 잘라서 리스트로 만들어 주는 함수이다.
print(s3)
print(&#39;:&#39;.join(s3)) #join -&gt; &#39;:&#39;(매개변수로 들어온)를 넣어서 문자열을 합쳐서 반환해주는 함수</p>
<p>a=&#39;life is too long&#39;
b=a.replace(&#39;life&#39;, &#39;Your leg&#39;)
print(b)</p>
<pre><code>
3. 묶음형(집힙형) 자료형 : list - 순서 o, 수정 가능</code></pre><p>a= [1,2,3]; b=[10, a, 12.5,  True, &#39;금쪽이&#39;]
print(a, type(a), id(a))
print(b, type(b), id(b))
aa =[]
bb= list()
print(type(aa), type(bb))</p>
<pre><code></code></pre><p>family=[&#39;엄마&#39;,&#39;아빠&#39;,&#39;나&#39;,&#39;형&#39;]
print(family[2]) # 인덱싱
print(family[0:2])# 슬라이싱- 0~1번까지
family.append(&#39;단풍이&#39;) # append() - 추가 - 맨뒤에 붙음
family.insert(0, &#39;할아버지&#39;) # 삽입 - 0번째에 넣어라
family.extend([&#39;외삼촌&#39;, &#39;큰누나&#39;]) #추가
family += [&#39;작은이모&#39;, &#39;큰이모&#39;] 
family.remove(&#39;단풍이&#39;) # remove는 밸류를 삭제 
del family[2] # del은 순서에 의한 삭제,  아빠 지워짐 - 2번째 지워짐
print(family, len(family))
print(family.index(&#39;나&#39;))
print(&#39;엄마&#39; in family, &#39;할머니&#39; in family) # 있는지 확인하는거 
del family # 변수를 삭제</p>
<pre><code>
- 중첩 list
</code></pre><p>aa =[1,2,3,[&#39;a&#39;, &#39;kbs&#39;, &#39;c&#39;],4,5] #중첩 list
print(aa)
print(aa[0])
print(aa[3])
print(aa[3][1]) # 3번째 꺼에서 1번째 꺼 - kbs만 나옴</p>
<p>print(id(aa))
aa[0] = 333 # 요소값 수정 가능
print(aa, id(aa))</p>
<p>print()
aa2=[&#39;123&#39;, &#39;34&#39;, &#39;234&#39;]
print(aa2)
aa2.sort() # 사전형식으로 정렬
print(aa2)
aa2.sort(key=int, reverse=True) # 문자를 숫자처럼 하고 가장 큰수부터 나열 
print(aa2)</p>
<pre><code></code></pre><p>name=[&#39;소현&#39;, &#39;금쪽이&#39;, &#39;다정&#39;]
print(name)
name2 = name   # 얕은 복사 : 주소 치환 / 자바 와 파이썬은 소멸자가 없다 (일정시간이 지나면 메모리가 자동 소멸)
print(id(name), id(name2))</p>
<p>import copy
name3 =copy.deepcopy(name) # 깊은 복사. 새로운 객체로 생성</p>
<p>print(id(name), id(name2), id(name3))
name[0] = &#39;용환&#39;
print(name)
print(name2)
print(name3)</p>
<pre><code>- 참고</code></pre><p>print(&quot;stack, queue&quot;) #stack : LiFO(last),  queue : FiFO(first)
sbs=[1,2,3]
sbs.append(4)
print(sbs)
sbs.pop()
print(sbs)
sbs.pop()
print(sbs) #뒤에서 부터 빠져나감.</p>
<p>print()
sbs=[1,2,3]
sbs.append(4)
sbs.pop(0)
print(sbs)
sbs.pop(0)
print(sbs) #앞에서 부터 빠져나감.</p>
<pre><code>4. tuple - list와 유사하나 읽기 전용. 순서O, 수정 불가</code></pre><p>t = (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;a&#39;)
#t = &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;a&#39; 
print(t, type(t),len(t), t.count(&#39;a&#39;), t.index(&#39;b&#39;))</p>
<p>print(t[0])
#t[0] = &#39;k&#39; # &#39;tuple&#39; object does not support item assignment - 수정 불가</p>
<p>imsi =list(t)
print(imsi, type(imsi))
imsi[0] = &#39;k&#39;
t = tuple(imsi)
print(t)</p>
<p>print()
print((1), type((1)))
print((1,), type((1,))) # ,를 찍어야 튜플로 인정된다(반드시).</p>
<p>print()
t1=(10,20)
a, b = t1
b, a = a, b
t2 =a,b
print(t2)</p>
<pre><code>5. set - 순서가 없다, 중복이 불가하다! (순서X, 중복X)</code></pre><p>print(&#39;----------set-----------&#39;)</p>
<h1 id="set---순서가-없다-중복이-불가하다-순서x-중복x">set - 순서가 없다, 중복이 불가하다! (순서X, 중복X)</h1>
<p>a={1,2,3,1}
print(a, type(a), len(a))</p>
<p>b={3,4}</p>
<p>print(a.union(b)) # 합집합
print(a.intersection(b)) # 교집합
print(a-b)   # 차집합
print(a | b) # 합집합
print(a &amp; b) # 교집합</p>
<p>print()
print(a)
#print(a[0]) -&gt; err 순서가 없기 때문에 에러발생
#a[0]=100 -&gt; &#39;set&#39; object does not support item assignment - set은 순서가 없다</p>
<p>a.update({4,5}) # .update함수를 통해 수정이(추가) 가능함.
a.update([6,7,8])
a.update((9,))
print(a)</p>
<p>a.discard(3) # 값에 의한 삭제(순서에 의한 삭제는 없다)
a.remove(5)  # 값에 의한 삭제
a.discard(3) # 값에 의한 삭제 - 해당 값이 없으면 통과한다.
#a.remove(5) # 값에 의한 삭제 - 해당 값이 없으면 에러가 발생한다.
print(a)</p>
<p>c=set()
c=a
print(c)
a.clear() # 날리는거
print(a)
print(c)</p>
<p>print()
li=[1,2,3,1,2,3]
print(li)
imsi=set(li) # 중복 배제
li=list(imsi) 
print(li)</p>
<pre><code>6. dict : {&#39;key&#39;:&#39;value&#39;} - 순서X, key를 이용해 value를 참조, JSON과 잘맞음</code></pre><p>print(&#39;----------dict-----------&#39;)</p>
<h1 id="사전형--keyvalue---순서x-key를-이용해-value를-참조-json과-잘맞음">사전형 : {&#39;key&#39;:&#39;value&#39;} - 순서X, key를 이용해 value를 참조, JSON과 잘맞음</h1>
<p>my = dict(k1=1,k2=&#39;mbc&#39;, k3=3.4)
print(my, type(my))</p>
<p>dic={&#39;파이썬&#39;:&#39;뱀&#39;, &#39;자바&#39;:&#39;커피&#39;, &#39;스프링&#39;:&#39;용수철&#39;, &#39;점수&#39;:[60,70,80]}
print(dic, type(dic), len(dic))
print(dic[&#39;자바&#39;])
#print(dic[0])  -&gt; 순서가 없어서 err발생</p>
<p>dic[&#39;오라클&#39;]=&#39;예언자&#39; # 추가 가능함
print(dic)</p>
<p>del dic[&#39;오라클&#39;] # 삭제
dic.pop(&#39;파이썬&#39;)
print(dic)</p>
<p>dic[&#39;자바&#39;]=&#39;웹용언어&#39; # 수정이 가능
print(dic)</p>
<p>print(dic.keys())
print(dic.values())
print(&#39;파이썬&#39; in dic)</p>
<pre><code>- 정리</code></pre><p>&#39;&#39;&#39;
str : 순서O, 수정X
list: 순서O, 수정O []
tuple:순서O, 수정X ()
set : 순서X, 수정X, 중복X {}
dict: 순서X, 키에 의한 value 참조 {:}
&#39;&#39;&#39;
```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python-1]]></title>
            <link>https://velog.io/@hs_0919/Python-1</link>
            <guid>https://velog.io/@hs_0919/Python-1</guid>
            <pubDate>Mon, 14 Nov 2022 15:40:57 GMT</pubDate>
            <description><![CDATA[<h4 id="1-변수-선언">1. 변수 선언</h4>
<pre><code>var1= &#39;안녕&#39;
print(var1)
var1=5
print(var1)

A=1; a=2; # 변수는 대소문자 구별함
print(&#39;A+a&#39;,A + a, id(A), id(a))
# A+a 3 2039314475312 2039314475344</code></pre><p>변수 선언시 type은 선언하지 않는다.</p>
<h4 id="2-값의-주소비교">2. 값의 주소비교</h4>
<pre><code>print()
a=10
b=12.5
c=b 
print(a, &#39;&#39;, b, &#39;&#39;, c)
# 10  12.5  12.5

print(&#39;주소출력 :&#39;, id(a), &#39;&#39;, id(b),&#39;&#39;, id(c))
# 주소출력 : 2039314475600  2039324178608  2039324178608
# b와 c 는 같은 주소를 가지고 있다. 절대 주소는 아니다.

print(a is b, a==b) # False False - 주소 비교, 값 비교
print(c is b, c==b) # True True - is는 결과를 true, false로 답한다.

aa = [1000]
bb = [1000]
print(aa == bb, aa is bb) # True False
print(id(aa), &#39;&#39; , id(bb))
# 2039324349312  2039324347328
# aa 와 bb의 값이 같지만 주소는 같지 않다.</code></pre><h4 id="3-주석-표기">3. 주석 표기</h4>
<pre><code># 한줄 주석
&#39;&#39;&#39;
여러줄 주석
&#39;&#39;&#39; 
&quot;&quot;&quot;
여러줄 주석
&quot;&quot;&quot; </code></pre><h4 id="4-keyword">4. keyword</h4>
<pre><code>import keyword
# 키워드(Keyword)는 파이썬에서 이미 예약되어있는 문자열로 다른 용도로 사용이 불가능하여 변수로 설정 안된다 오류난다.
print(&#39;키워드(예약어)목록 : &#39;, keyword.kwlist)
# 키워드의 리스트 목록</code></pre><h4 id="5-자료형">5. 자료형</h4>
<pre><code>print(3, type(3)) # int(정수) 타입
print(3.4, type(3.4)) # float(실수) 타입
print(3 + 4j, type(3+4j)) # complex(복소수) 타입
print(True, type(True)) # boolean 타입
print(&quot;good&quot;, type(&#39;good&#39;)) # string 타입

print((1,), type((1,)))# (1,) 튜플 타입
print([1], type([1])) # [1] 리스트
print({1}, type({1})) # {1} set 타입
print({&#39;k&#39;:1}, type({&#39;k&#39;:1})) # {&#39;k&#39;: 1} 딕셔너리

print(isinstance(1, int)) #type을 확인하는 연산자. True
print(isinstance(1.2, float))
# True</code></pre><h4 id="6-치환">6. 치환</h4>
<pre><code>v1=2 #치환
v1=v2=v3=v4=5
print(v1,v2,v3,v4) # 5 5 5 5

v1=1,2,3
print(v1) # (1, 2, 3)

v1,v2=10,20
print(v1,v2) # 10 20
v2,v1=v1,v2
print(v1, v2) # 20 10</code></pre><h4 id="7-값-할당-packing">7. 값 할당 packing</h4>
<pre><code>*v1,v2 = 1,2,3,4,5
v1,*v2 = 1,2,3,4,5
#*v1,*v2 = 1,2,3,4,5 - 에러가 발생한다.
print(v1) # 1
print(v2) # [2, 3, 4, 5]

*v1,v2,v3=1,2,3,4,5
print(v1,v2,v3) # [1, 2, 3] 4 5</code></pre><p>packing은 여러개의 변수를 하나에 담는것이다.</p>
<h4 id="8-연산자">8. 연산자</h4>
<pre><code>print(5+3,5-3,5*3,5/3) # 8 2 15 1.6666666666666667
print(5 // 3, 5%3, divmod(5,3)) # 몫 과 나누기 1 2 (1, 2)</code></pre><br>

<p>연산자 우선순위</p>
<pre><code>print(&#39;연산자 우선순위&#39;, 3+4*5, (3+4)*5) # 23 35
# 소괄호 () &gt; 산술 연산자(**거듭제곱 &gt; *,/ &gt; +, -) &gt; 관리연산자 &gt; 논리연산자 &gt; 치환(=)</code></pre><br>

<p>관계연산자(== 값이 같은지, != 값이 다른지)</p>
<pre><code>print(5&gt;3, 5==3, 5 != 3)
# True False True</code></pre><br>

<p>논리연산자</p>
<ul>
<li>and : 모두 true어야 true반환</li>
<li>or  : 둘 중 하나만 true여도 true 반환</li>
<li>not : 반대로 해석, 만약 a가 true면 false, b가 false면 true를 반환<pre><code>print(5&gt;3 and 4&lt;3, 5&gt;3 or 4&lt;3, not(5&gt;=3))
# False True False</code></pre><br>

</li>
</ul>
<pre><code># 문자열 더하기 연산자
print(&#39;파이썬&#39;+&#39;만&#39;+&#39;세&#39;) # 파이썬만세
print(&#39;파이썬&#39;*10)
# 파이썬파이썬파이썬파이썬파이썬파이썬파이썬파이썬파이썬파이썬</code></pre><br>

<pre><code># 누적
a=10
a= a+1
a += 1
#a++ 파이썬은 증감연산자 없다.
print(&#39;a:&#39;, a) # a: 12

print(a, a* -1, -a, --a)
# 12 -12 -12 12</code></pre><br>

<h4 id="9-출력-서식">9. 출력 서식</h4>
<pre><code>print(format(123.45678, &#39;10.3f&#39;)) #전체 10자리 확보하고 앞에 3자리 공백, 4번째 자리에서 반올림 하기
#   123.457
print(format(123.45678, &#39;10.3&#39;))
#  1.23e+02
print(format(123, &#39;10d&#39;)) 
#       123
print (&#39;{0:.3f}&#39;.format(1.0/3)) # 소수 세번째자리 까지
#0.333
print (&#39;{0:_^11}&#39;.format(&#39;hello&#39;))
# ___hello___
print (&#39;{name} wrote {book}&#39;.format(name=&#39;Swaroop&#39;, book=&#39;A Byte of Python&#39;))
# Swaroop wrote A Byte of Python</code></pre><br>

<p>많이 사용하는것</p>
<pre><code>print(&#39;이름:{0}, 가격:{1}&#39;.format(&#39;마우스&#39;, 5000))
# 이름:마우스, 가격:5000
print(&#39;이름:{0}, 가격:{1}&#39;.format(&#39;마우스&#39;, 5000))
# 인덱스를 쓰지않아도 순서대로 들어옴, 이름:마우스, 가격:5000
print(&#39;이름:{1}, 가격:{0}&#39;.format(&#39;마우스&#39;, 5000))
# 이름:5000, 가격:마우스
print(&#39;이름:{1}, 가격:{0}, 가격:{0} &#39;.format(&#39;마우스&#39;, 5000))
# 이름:5000, 가격:마우스, 가격:마우스

print(&#39;나는 나이가 %d 이다.&#39;%28) 
# 나는 나이가 28 이다.
print(&#39;나는 나이가 %s 이다.&#39;%&#39;스물여덟&#39;)# 문자
# 나는 나이가 스물여덟 이다.
print(&#39;나는 나이가 %d 이고 이름은 %s이다.&#39;%(23, &#39;홍길동&#39;))
# 나는 나이가 23 이고 이름은 홍길동이다.
print(&#39;나는 나이가 %s 이고 이름은 %s이다.&#39;%(23, &#39;홍길동&#39;))
# 나는 나이가 23 이고 이름은 홍길동이다.
print(&#39;나는 키가 %f이고, 에너지가 %d%%.&#39;%(177.7, 100)) 
#실수 ,%f - 소수6자리 정해짐.
#나는 키가 177.700000이고, 에너지가 100%.</code></pre><ul>
<li>%s : 문자열 치환, 그러나 어떤 자료도 다 치환된다.</li>
<li>%d : 정수 치환</li>
<li>%f : 소수점 치환, 소수점 6자리까지 정해진다.</li>
<li>%10(s,d,f) : 왼쪽으로부터 공백 10자리</li>
<li>%-10(s,d,f) : 오른쪽으로부터 공백 10자리</li>
<li>%% : % 표시<br>
```
print('aa\tbb') # \t - tab키
# aa    bb
print(r'aa\tbb')# 앞에 raw string(r)을 선행하면 이스케이프(\) 기능 해제 
# aa\tbb

</li>
</ul>
<p>print(&quot;c:\aa\abc\nbc.txt&quot;)
print(r&quot;c:\aa\abc\nbc.txt&quot;)# 앞에 raw string(r)을 선행하면 이스케이프() 기능 해제 </p>
<h1 id="bctxt">bc.txt</h1>
<p>print(&#39;aa&#39;, end=&#39;, &#39;) </p>
<h1 id="print-는-기본적으로-라인스킵이-있다-end-를-사용하면-라인스킵이-안됨">print 는 기본적으로 라인스킵이 있다. end=&#39;&#39; 를 사용하면 라인스킵이 안됨.</h1>
<p>print(&#39;bb&#39;)</p>
<h1 id="aa-bb">aa, bb</h1>
<p>```</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python]]></title>
            <link>https://velog.io/@hs_0919/Python</link>
            <guid>https://velog.io/@hs_0919/Python</guid>
            <pubDate>Tue, 08 Nov 2022 15:40:50 GMT</pubDate>
            <description><![CDATA[<h1 id="이클립스-기본-설정하기">이클립스 기본 설정하기</h1>
</br>

<h2 id="1-인코딩-설정">1. 인코딩 설정</h2>
<ul>
<li>이클립스 상단에 <code>window</code> 클릭 후 <code>Preferences</code> 눌러서 <strong>encoding</strong> 검색.</li>
<li><em>workspace</em>, <em>css files</em>, <em>html files</em>, <em>jsp files</em>, <em>xml files</em> 눌러서 encoding부분 <code>utf-8</code>로 설정하기.</li>
</ul>
<h2 id="2-font-설정">2. font 설정</h2>
<ul>
<li>이클립스 상단에 <code>window</code> 클릭 후 <code>Preferences</code> 눌러서 <strong>font</strong> 검색.</li>
<li><code>Appearance</code> - <code>color and fonts</code> - <code>Basic</code> - <code>Text Font</code> 클릭하면 글꼴, 글꼴크기를 설정할 수 있는 창이 나온다.</li>
</ul>
<h2 id="3-주석-색-바꾸기">3. 주석 색 바꾸기</h2>
<ul>
<li>이번 python 공부는 eclipse를 사용하기 때문에 PyDev가 설치 되어있는 전제로 설명하겠다.</li>
<li>PyDev 설치 방법은 검색하면 자세하게 알려주기 때문에 여기서는 생략 하겠다.</li>
<li>이클립스 상단에 <code>window</code> 클릭 후 <code>Preferences</code> 눌러서 <strong>editor</strong> 검색.</li>
<li><code>PyDev</code> - <code>Editor</code> 를 클릭하면 색을 바꿀 수 있으므로 자신이 원하는 색으로 변경하면 된다.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[React 기본]]></title>
            <link>https://velog.io/@hs_0919/React-%EA%B8%B0%EB%B3%B8</link>
            <guid>https://velog.io/@hs_0919/React-%EA%B8%B0%EB%B3%B8</guid>
            <pubDate>Mon, 31 Oct 2022 15:17:23 GMT</pubDate>
            <description><![CDATA[<ol>
<li><p>react는 여러가지 component를 가지고 있고 각 component가 한개 또는 여러개의 기능을 가지고있다.</p>
</li>
<li><p>component에는 함수형 component가 있고 첫글자는 대문자로 시작해야한다.</p>
</li>
</ol>
<ol start="3">
<li><p>React에서 css 사용하는 법<br/>
 1) inline css 사용하기</p>
<ul>
<li><p>css파일을 따로작성할 필요없이 html태그에 적는 것이다. </p>
</li>
<li><p>하지만, 특별한 경우가 아니고서는 잘 사용하지 않는다.</p>
<p>2) App.css, index.css 활용하기</p>
</li>
<li><p>index.css는 전체 프로젝트에 영향을 미친다.</p>
</li>
<li><p>App.css app 관련된것만 영향을 미칠거 같지만 전체에 영향을 미친다.</p>
<p>3) css module 사용하기</p>
</li>
<li><p>파일명을 적고 .module.css 라고 적는다.</p>
</li>
<li><p>가장 많이 사용하는 방법이고, 동일한 name으로 작성되어도 중복될 일이 없다. </p>
</li>
<li><p>글로벌단위로 관리되는것이 아니라 component 단위로 관리 되기때문에 관리하기가 편리하다.</p>
</li>
</ul>
</li>
<li><p>이벤트 처리 방법</p>
</li>
</ol>
<ul>
<li><p>미리 함수를 하나 만들어서 사용하기.</p>
<pre><code>export default function Hello(){
  function ShowName(){
      console.log(&quot;mike&quot;);
  }
  return (
      &lt;div&gt;   
          &lt;h1&gt;Hello&lt;/h1&gt;
          &lt;World /&gt;
          &lt;button onClick={ShowName}&gt;Show name&lt;/button&gt;
      &lt;/div&gt;
  );
}</code></pre></li>
<li><p>-<code>function ShowName(){}</code> 이라는 함수를 만들어서 <code>onClick={}</code> 안에 ShowName(함수명)을 적어주면 된다. 이러면 콘솔창에 mike가 뜨는걸 확인할 수 있다.</p>
</li>
<li><p>내부에 직접 함수를 작성하기.</p>
<pre><code>export default function Hello(){
  return (
      &lt;div&gt;   
          &lt;h1&gt;Hello&lt;/h1&gt;
          &lt;World /&gt;
          &lt;button onClick={()=&gt;{
              console.log(&quot;mike&quot;)
          }}&gt;Show name&lt;/button&gt;
      &lt;/div&gt;
  );
}</code></pre></li>
</ul>
<p>-- <code>&lt;button onClick={()=&gt;{
                console.log(&quot;mike&quot;)
            }}&gt;Show name&lt;/button&gt;</code>안에 직접 함수를 작성하여 불러오는 방법이다. 이렇게 만들어도 버튼을 클릭하면 console 창에 mike가 표시된다. --&gt; 이 방법의 장점은 매개변수를 전달하기 편하다는 것이다.</p>
<br/>

<blockquote>
<p>출처 : <a href="https://www.youtube.com/c/%EC%BD%94%EB%94%A9%EC%95%99%EB%A7%88/featured">유뷰브 코딩앙마</a></p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[React 실행]]></title>
            <link>https://velog.io/@hs_0919/React%EB%A1%9C-%EB%8B%A8%EC%96%B4%EC%9E%A5-%EB%A7%8C%EB%93%A4%EA%B8%B0-1</link>
            <guid>https://velog.io/@hs_0919/React%EB%A1%9C-%EB%8B%A8%EC%96%B4%EC%9E%A5-%EB%A7%8C%EB%93%A4%EA%B8%B0-1</guid>
            <pubDate>Sun, 30 Oct 2022 15:17:18 GMT</pubDate>
            <description><![CDATA[<h2 id="react-실행">React 실행</h2>
<h3 id="1-작업할-폴더-및-경로설정">1. 작업할 폴더 및 경로설정</h3>
<ul>
<li><p>작업할 경로를 설정했다면 그 경로를 복사하고 cmd를 열어 <code>cd 복사한 경로</code> 입력.<img src="https://velog.velcdn.com/images/hs_0919/post/b4575966-f63e-49c7-96ba-2ad4d3f45c31/image.png" alt=""></p>
</li>
<li><p><code>npx create-react-app voca</code> 를 입력하면 설치가 진행되면서 프로젝트가 하나 생성이 된다.
<img src="https://velog.velcdn.com/images/hs_0919/post/6ee55e37-a180-4b0e-9068-7e204e0d5c15/image.png" alt="">
<img src="https://velog.velcdn.com/images/hs_0919/post/6eec0175-43d4-4c60-bc74-64807fbaea1b/image.png" alt=""> </p>
</li>
<li><p>create-react-app 은 쉽고 빠르게 모든것을 구현시켜준다.</p>
</li>
<li><p>vs code를 실행시켜 확인해보면
<img src="https://velog.velcdn.com/images/hs_0919/post/e3392c8f-9d91-421d-b5cf-666772c88eec/image.png" alt="">
잘 설치가 되어있는지 확인할 수 있다.</p>
</li>
<li><p>터미널을 열어서 <code>npm start</code> 를 입력하여 리액트 창이 하나 열리면 잘 설치가 된것이다.</p>
</li>
</ul>
<h3 id="2-살펴보기">2. 살펴보기</h3>
<ul>
<li><p><strong>node_modules</strong> - 이 프로젝를 실행할때 사용하는 <code>dependencies</code> 가 모두 모여있는 곳으로,  package.json파일을 통해 볼 수 있다. 이 폴더를 지우면 프로젝트를 띄울 수 없다.
또한 , <strong>node_modules</strong>는 용량이 크기 때문에 깃에 올릴때 같이 올리지 않는다. 나중에 사용자가 필요시 npm install를 통해 다시 설치가 가능하다.</p>
</li>
<li><p><strong>index.html</strong> - <em>public</em> 폴더 안에있는 index.html을 보면<code>&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;</code> 를 통해 react코드가 실행이 되어 만들어진 돔이 구현이 된다.</p>
</li>
<li><p><strong>App.js</strong> - <em>src</em> 폴더안에 있고, 여기서 코드를 작성하면 리액트 화면에 바로 표시가 된다.</p>
</li>
<li><p><strong>package.json</strong> - 
<code>&quot;start&quot;: &quot;react-scripts start&quot;</code> - 개발모드로 프로그램을 실행한다.
<code>&quot;build&quot;: &quot;react-scripts build&quot;</code> - 실제 배포모드로 만들어 준다.
<code>&quot;test&quot;: &quot;react-scripts test&quot;</code> - test
<code>&quot;eject&quot;: &quot;react-scripts eject&quot;</code> - 내부 설정파일을 꺼내는 역할</p>
</li>
</ul>
<blockquote>
<p>출처 : <a href="https://www.youtube.com/c/%EC%BD%94%EB%94%A9%EC%95%99%EB%A7%88/featured">유뷰브 코딩앙마</a></p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[Node.js 설치]]></title>
            <link>https://velog.io/@hs_0919/Node.js-%EC%84%A4%EC%B9%98</link>
            <guid>https://velog.io/@hs_0919/Node.js-%EC%84%A4%EC%B9%98</guid>
            <pubDate>Tue, 25 Oct 2022 16:24:33 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>Node.js는 확장성 있는 네트워크 애플리케이션(특히 서버 사이드) 개발에 사용되는 소프트웨어 플랫폼이다. 작성 언어로 자바스크립트를 활용하며 논블로킹(Non-blocking) I/O와 단일 스레드 이벤트 루프를 통한 높은 처리 성능을 가지고 있다.
 내장 HTTP 서버 라이브러리를 포함하고 있어 웹 서버에서 아파치 등의 별도의 소프트웨어 없이 동작하는 것이 가능하며 이를 통해 웹 서버의 동작에 있어 더 많은 통제를 가능케 한다.</p>
</blockquote>
<h2 id="📖nodejs-설치하기">📖Node.js 설치하기</h2>
<ul>
<li>링크를 클릭해서 Node.js설치하기<blockquote>
<p><a href="https://nodejs.org/ko/">Node.js</a></p>
</blockquote>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/hs_0919/post/1c9996a6-6115-4a23-b2dd-09adb47b1450/image.png" alt=""></p>
<ul>
<li>여기서 LTS 나 Current버전 둘 중 아무거나 다운받아도 상관없다.<ul>
<li>LTS 버전이 신뢰도와 안정성이 높고, 기업에서 많이 사용한다고 한다.<ul>
<li>Current 버전은 개발자들 학습용으로 쓰인다고 한다.
둘 중 아무거나 상관없으니 클릭해서 설치!</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/hs_0919/post/70635820-3d18-47f5-8df1-22e23fad4021/image.png" alt=""></p>
<ul>
<li>다운받고 실행시키면 이러한 화면이 나오고 Next 클릭
<img src="https://velog.velcdn.com/images/hs_0919/post/4028b50b-f555-4c04-82aa-8823b8d7b211/image.png" alt=""></li>
<li>이부분은 파이썬이나 비주얼 스튜디오 에서 필요한 도구를 자동 설치 여부를 묻는것이다.
<img src="https://velog.velcdn.com/images/hs_0919/post/aa377577-219f-4967-87a7-59fe124dbf09/image.png" alt=""></li>
<li>이런 화면이 뜨고 엔터키를 누르면 창이 없어진다.</li>
</ul>
<h2 id="📖nodejs-설치확인-하기">📖Node.js 설치확인 하기</h2>
<ul>
<li>명령 프롬프트 (cmd)나 Node.js 명령 프롬프트를 실행시켜서
<img src="https://velog.velcdn.com/images/hs_0919/post/10dae407-7fee-4c7d-bb9d-2fb75d09b7ec/image.png" alt="">
<code>npm -v</code> 나 <code>node -v</code> 를 입력하면 현재버전과 설치가 되어있는것을 확인할 수 있다.</li>
</ul>
<h4 id="출처--httpskowikipediaorgwikinodejs">출처 : <a href="https://ko.wikipedia.org/wiki/Node.js">https://ko.wikipedia.org/wiki/Node.js</a></h4>
]]></description>
        </item>
        <item>
            <title><![CDATA[R Studio 설정]]></title>
            <link>https://velog.io/@hs_0919/R-Studio-%EC%84%A4%EC%A0%95</link>
            <guid>https://velog.io/@hs_0919/R-Studio-%EC%84%A4%EC%A0%95</guid>
            <pubDate>Sun, 23 Oct 2022 16:21:37 GMT</pubDate>
            <description><![CDATA[<h3 id="1-경로-설정하기">1. 경로 설정하기</h3>
<ul>
<li>먼저 경로를 설정해준다.
<img src="https://velog.velcdn.com/images/hs_0919/post/4201b59b-686f-43e2-8929-70b568582975/image.png" alt=""></li>
<li>상단 탭 Tools에 가서 Global Options... 클릭
<img src="https://velog.velcdn.com/images/hs_0919/post/cf16c2c9-063a-4b68-a14b-8edb2a28ed6e/image.png" alt=""></li>
<li>Browse를 클릭하여 사용하고자 하는 폴더를 선택하면 경로설정 끝.
<img src="https://velog.velcdn.com/images/hs_0919/post/b55ec445-385f-4505-938a-3b2782e9c8bd/image.png" alt=""></li>
<li>경로 설정을 하였다면 표시된 부분에 경로가 설정된 것을 확인할 수 있다.</li>
</ul>
<h3 id="2-폰트-및-인코딩-설정">2. 폰트 및 인코딩 설정</h3>
<h4 id="🖋-폰트-설정">🖋 폰트 설정</h4>
<ul>
<li>상단 탭 Tools에 가서 Global Options... 클릭
<img src="https://velog.velcdn.com/images/hs_0919/post/2efbfdca-070e-4510-9f26-1516dd542de7/image.png" alt="">
<img src="https://velog.velcdn.com/images/hs_0919/post/9fcc3ef7-980f-4fad-bdeb-da318434d63b/image.png" alt=""></li>
<li><ul>
<li>RStudio theme : R Studio 테마 선택</li>
<li>Zoom : 확대, 축소</li>
<li>Editor font : 폰트 설정</li>
<li>Editor font size : 폰트 사이즈 설정</li>
<li>Editor theme : 코드 테마설정(미리보기가 있어 보고 선택할 수 있다.)</li>
</ul>
</li>
</ul>
<h4 id="📃-인코딩-설정">📃 인코딩 설정</h4>
<ul>
<li>상단 탭 Tools에 가서 Global Options... 클릭
<img src="https://velog.velcdn.com/images/hs_0919/post/2efbfdca-070e-4510-9f26-1516dd542de7/image.png" alt="">
<img src="https://velog.velcdn.com/images/hs_0919/post/c3017400-56fb-4da3-9d20-e3c8825e5342/image.png" alt=""></li>
<li>code - saving - Default text encoding 에서 Change 클릭
<img src="https://velog.velcdn.com/images/hs_0919/post/47fcb3b0-971f-4513-a32c-f26bfc67a3c1/image.png" alt=""></li>
<li>UTF-8 선택하고 ok 클릭 후 다시 ok 클릭하면 인코딩 설정 완료!</li>
</ul>
]]></description>
        </item>
    </channel>
</rss>