E D R , A S I H C RSS

02_Python


1. 02 Python Seminar


  • 02 •™ฒˆ ›„ฐฐ“ค—๊ฒŒ –ธ–˜ ๊ธฐˆ. ––๊ฒŒ ƒ๊ฐ•˜ C ‹คŠ” ๊ธฐˆฅผ žก๊ธฐŠ” ” ‰ฝ๊ณ  ” นœˆ™•˜๊ฒŒ –ธ–ฅผ ฐฐšธˆ˜ žˆ‹คŠ” ทจ€•˜— „ ƒ
  • Class ๊ฐœ… ๊นŒ€Š” “ค–๊ฐ€€ •Š„ ˜ˆ • .. •„ง๊นŒ€Š” •ˆ˜ ๊ฐœ… žก๊ธฐ๊ฐ€ ฐ” ๊บผผŠ” ƒ๊ฐ “ฌ
  • žฃŒ˜•, —ฐ‚ฐž , ๊ธฐณธฌธ• , •ˆ˜ , “ˆ„ ค‘  œผกœ ‹คฃฐ ˜ˆ •ž„
  • ˜ˆฅผ ––๊ฒŒ —ฌค„๊นŒ๊ฐ€ -_- ๊ณ ฏผจ -_- (––๊ฒŒ“ค • ๊นŒš” ?)

2. ๊ฐ•‚ฌ ฐ ผ •

  • ๊ฐ•‚ฌ = 00 ผ
  • ผ • = ™•‹คžˆ  ••€€ •ŠŒ

3. Goal


  • ๊ทธ“ค –ธ– ฌธ•— – ค›€„ Аผ€ •Š•˜œผ ข‹๊ฒ ‹คŠ” ฐ”žจ
  • •„ -_- ”„ ง๊ณ  10… ƒงŒ „ธฏธ‚˜— ™”œผ •˜Š” ฐ”žจ
  • ‚๊ฐ€ ˜„ก ‰ฝ๊ฒŒ ›„ฐฐ“ค—๊ฒŒ ๊ฐ€ณค„ˆ˜ žˆ—ˆŒ •˜Š” ฐ”žจ
    Who is "‚" here? - ผšฉ :)
  • งˆ€ง‰œผกœ ›„ฐฐ“ค๊ณผ ๊ฐ™ ŒŒฌ Šค„ฐ””ฅผ • ˆ˜ žˆ๊ธฐฅผ ฐ”ผŠ” ฐ”žจ

4. Related Document or book


  • Œ€€ถ„˜  •Š” Learning Python —„œ ฐœตœ .. ๊ทธฑ… ๊ฐ€žฅ ‰ฌšธ๊บผ ๊ฐ™Šต‹ˆ‹ค.

5. Date of Seminar


  • •„ง ฏธ •ž…‹ˆ‹ค นจฆฌ •˜„ก ••ฃ 

6. Main Contents


6.1. ŒŒฌ€ —ˆธ๊ฐ€?


  • ๊ฐ€žฅ  •™••˜๊ฒŒ ง•˜ž ๊ฐ €–ฅ Šคฌฆฝ –ธ–‹ค. (see also Ousterhout's IEEE Computer article Scripting: Higher Level Programming for the 21st Century at http://home.pacbell.net/ouster/scripting.html )
  • ‚ฌšฉ•˜๊ธฐ ‰ฝ๊ณ  , ฐฐšฐ๊ธฐ ‰ฌšฐฉฐ —ฌŸฌ ฐฉ–ฅœผกœ šฉ• ˆ˜ žˆŠ” –ธ–‹ค.
  • GUI , ‹œŠค…œ œ ‹ธฆฌ‹ฐ , AI , ธ„ฐ„ท ŠคฌฆฝŒ… “ฑ— ‚ฌšฉ• ˆ˜ žˆŠ” –ธ–‹ค.
  • C, C++, Java — น„• ƒ‹นžˆ ‰ฌš ฌธ• ๊ตฌกฐฅผ ๊ฐ€€๊ณ  žˆ‹ค
  • (RCM ฐจ„ธŒ€ –ธ–˜ Šน•œผกœ ๊ผฝŠ”) ™ žฃŒ˜• ๊ฐ€–ฅ –ธ–

see also http://fallin.lv/PythonRumors

6.2. ŒŒฌ ‚ฌšฉœ ˜ˆ


  • Red Hat˜ ฆฌˆ…Šค ธŠค†จŸฌธ •„‚˜ฝ˜‹คŠ” ŒŒฌœผกœ งœ—ฌ ธ žˆ‹ค
  • Infoseek ž€ ฌƒˆ ‹ธŠธŠ” ผ€ ๊ฒ€ƒ‰—”ง„„ ŒŒฌ ๊ธฐฐ˜œผกœ ‚ฌšฉ•œ‹ค
  • NASA Š” ž„  œ– ‹œŠค…œ— ŒŒฌ„ ‚ฌšฉ•œ‹ค
  • Industrial Light and Magic ‚ฌŠ” ŒŒฌ„ ‚ฌšฉ•˜—ฌ ๊‘๊ณ šฉ —‹ˆฉ”…˜„  œž‘•œ‹ค
  •  œ„‚คŽ˜€Š” ŒŒฌ„ šฉ•œ cgi กœ งŒ“ค–กŒ‹ค

6.3. ŒŒฌ˜ Šน•

  • Œ€™”‹ … น–‰‹ค
    C ‚˜ C++ € †ŒŠคฅผ •œ๊บผฒˆ— ‹ค น˜๊ณ „œ ‚˜ค‘— "ŒŒผ" •˜Š”‹€งŒ Python ˜ ๊ฒฝšฐ ž‹  “ฐŠ” ผธงˆ‹ค ฝ˜€“ค–๊ฐ„‹ค.
  • “ˆ ŒŒผ ‹ค–‰‹ค
    “ˆž€ C ‚˜ C++ ˜ header ŒŒผ ฒ˜Ÿผ ๊ฐ๊ฐ˜ … น–ฅผ ‹ฎ๊ณ žˆŠ” ๊ฒƒ˜ ง‘•‹ค.
  • “  š˜ …ฆฝ ‹ค
    žฐ”™€ ๊ฐ™ VM จธ‹ ƒ—„œ Œ•„๊ฐ€Š” ก €กœ š˜ œ …ฆฝ ‹ค.

6.4. C ™€ C++ ๊ณผ Java ™€ Python ˜ ๊ฐ„‹จ•œ †ŒŠค น„๊ต


6.4.1. Hello World for C

~cpp 
    #include <stdio.h>

    int main(void)
    {
        printf("Hello World\n");

        return 0;
    }

6.4.2. Hello World for C++

~cpp 
    #include <iostream.h>
    int main()
    {
         cout << "Hello World\n" ;
         return 0;
    }

6.4.3. Hello World for Java

~cpp 
    public class HelloWorldExample
    {
      public static void main(String[] args)
      {
        System.out.println("Hello World");
      }
    }

6.4.4. Hello World for Python

~cpp 
    Print "Hello World"

6.4.5. Quick Sort in Python

~cpp 
def qsort(aList): 
        if not aList: 
                return [] 
        ltList=[y for y in aList[1:] if y<aList[0]] 
        gtList=[y for y in aList[1:] if y>=aList[0]] 
        return qsort(ltList)+[aList[0]]+qsort(gtList) 

6.5. žฃŒ˜•๊ณผ —ฐ‚ฐž


6.5.1. ŒŒฌ ”„กœ๊ทธžจ€ “ˆ(module), ฌธ(statement), ๊ทธฆฌ๊ณ  ๊ฐ(object) กœ ๊ตฌ„ฑœ‹ค.

~cpp           1. ”„กœ๊ทธžจ€ “ˆกœ ๊ตฌ„ฑ˜– žˆ‹ค. 
         2. “ˆ€ ฌธ„ ฌ••œ‹ค. 
         3. ฌธ€ ๊ฐฅผ ƒ„ฑ•˜๊ณ  ฒ˜ฆฌ•œ‹ค. 


  • ŒŒฌ€ ‚žฅ žฃŒ˜•„ ๊ธฐณธœผกœ •œ‹ค.
    '' ๊ธฐ C ‚˜ C++ ˜ ๊ฒฝšฐŠ” –– •œ €ˆ˜ฅผ € •• –„ ƒ€ž…„ ๊ผญ € •• ค˜•–ˆ‹ค ๊ทธ ˜ˆกœ int ‚˜ char  žˆ‹ค •˜€งŒ ŒŒฌ˜ ๊ฒฝšฐŠ”
    ž œผกœ žฃŒ˜•„ €›•„œ ‚˜˜ค€กœ –– •œ €ˆ˜˜•ธ€ € •„ •ฃผ€ •Š•„„ œ‹ค ''

~cpp 
ˆ˜น˜˜•   3.1415, 1234 , 999L 
ฌธž—   'spam', "guido's"
ฆฌŠคŠธ   [1,[2, 'three'],4]
‚ฌ „     {'food':'spam','taste':'yum'}
Šœ”Œ     (1,'spam',4,'U')
ŒŒผ     text=open('eggs', 'r').read()

6.5.2. ˆ˜น˜˜•

~cpp 
1234, -25,0            ผฐ˜ •ˆ˜ ฉฐ C˜ ๊ฒฝšฐ int — •‹น•œ‹ค.    
9999999999999L         Long ˜•  •ˆ˜ ‹ค.. long ˜•˜  •ˆ˜— Œ€•„œŠ” C ˜ long int ™€Š” ‹ค๊ฒŒ  •ˆ˜’ค— "L" งŒ ™ œ‹ค.
1.23, 3E210            €™†Œˆ˜ ฉฐ C˜ ๊ฒฝšฐ double — •‹น•œ‹ค.
0177, 0x9ff            8ง„ˆ˜, 16ง„ˆ˜ 

6.5.3. ฌธž—

~cpp 
s1 = ''                นˆ ฌธž— 
s2 = "spams"           ค‘ ธšฉ€˜ธ
block = """..."""      ‚ผค‘ ธšฉ€˜ธ
s1+s2                  —ฐ๊ฒฐ
s2*3                   ฐ˜ณต
s2[i]                  ธฑŠค
s2[1:j]                ŠฌผŠค
len(s2)                ๊ธธ
for x in s2            ฐ˜ณต

6.5.4. ฆฌŠคŠธ

  • ŒŒฌ˜ ๊ฐ€žฅ œ —ฐ•œ žฃŒ˜•€กœ ๊ฐ žฃŒ˜ ˆœ„œฅผ ๊ฐ–Š” ง‘•‹ค.
  • ๊ฐ ๊ฐ„˜ ˆœ„œฅผ ๊ฐ€€๊ฒŒ œ‹ค(index ฒˆ˜ธฅผ ๊ฐ€ง„‹ค)

~cpp 
L1 = []                นˆฆฌŠคŠธ
L2 = [0,1,2,3]         „ค ๊ฐœ˜ •ฉ: index Š” 0 ~ 3 ž„

6.5.5. ‚ฌ „

  • ฆฌŠคŠธ™€ น„Šท•˜‚˜ ฆฌŠคŠธ™€Š” ‹ค๊ฒŒ ๊ฐ ๊ฐ„˜ ˆœ„œฅผ ๊ฐ€€€ •ŠŠ” ๊ฐ“ค˜ ง‘•‹ค

~cpp 
d1 = {}                                    นˆ‚ฌ „
d2 = { 'spam':2, 'eggs':3 }                2๊ฐœ˜ ๊ฐ’„ ๊ฐ€€Š” ‚ฌ „
d3 = { 'food' : { 'ham':1, 'egg':2 } }     ‚ฌ

6.5.6. Šœ”Œ

  • ฆฌŠคŠธ™€ ๊ฐ™€ ฐฉ‹œผกœ ™ž‘•˜€งŒ ๊ฐ˜ ‚šฉ„ ฐ”๊ฟ€ˆ˜ —†‹ค.

~cpp 
()                    นˆ Šœ”Œ
t1 = (0,)             •œ ๊ฐœ˜ •Šœ”Œ
t2 = (0,1,2,3)        „ค ๊ฐœ˜ •Šœ”Œ

6.6. ๊ธฐณธฌธ

~cpp 

˜ธถœ                 •ˆ˜ ‹ค–‰            stdout.write("spam, ham.toast\n") 
ถœ ฅ                 ๊ฐ ถœ ฅ            print "THe killer", joke
If/elif/else      „ ƒ  ˆ˜–‰          if "python" in text:print text
For/else          ‹œ€€Šค ฐ˜ณต          for x in mylist: print x 
While/else        ผฐ˜ ธ ฃจ”„        while1:print "hello"
Pass              •„ผ„ •˜€ •ŠŒ   while1:pass
Break,Countinue   ฃจ”„  ”„            while1:if not line: break
Import, From      “ˆ  ‘๊ทผ            import sys; from sys import stdin
Def, Return       •ˆ˜ งŒ“ค๊ธฐ          def f(a,b,c=1, *d): return a+b+c+d[0]
Class             ๊ฐ งŒ“ค๊ธฐ          class subclass: staticData = []
Global            „คž„ ŠคŽ˜Šค        def function(): global x,y; x = 'new'
Del               ๊ฒ ‚ญ œ            def data[k]; del data[i:j]; del obj.attr

6.7. •ˆ˜ ™€ “ˆ


6.7.1. •ˆ˜™€€ จœ ฌธ

~cpp 

˜ธถœ                 myfunc("spam, ham, toast\n")
def, return       def adder(a,b,c=1, *d): return a+b+c+d[0]
global            def function(): global x,y; x = 'new'

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:04
Processing time 0.0251 sec