파이썬 기초

카테고리 없음 2013. 3. 29. 13:40 Posted by mathboy

>>> print 4

4

>>> print 2+2+2

6

>>> print "1"*3

111

>>> print 'print'*3

printprintprint


>>> test='test'

>>> test[0]

't'

>>> print test[0]

t


>>> pythagoras = 'There is geometry in the humming of the strings'

>>> print pythagoras.find('There')

0

>>> print pythagoras.find('string')

40

>>> print pythagoras[40:]

strings

>>> print pythagoras[20:]

 the humming of the strings

>>> print pythagoras[30:]

ng of the strings

>>> print pythagoras[35:]

 the strings

>>> print pythagoras.find('geometry')

9

>>> print pythagoras[9:]

geometry in the humming of the strings

>>> pythagoras = pythagoras + ' test'

>>> print pythagoras

There is geometry in the humming of the strings test

>>> pythagoras = pythagoras + 'test is the test of test'

>>> print pythagoras.find('test',1)

47

>>> print pythagoras[47:]

testtest is the test of test

>>> print pythagoras.find('test',0)

47

>>> print pythagoras.find('test',48)

51



>>> def inc(n):

...     return n+1

...

>>> inc(5)

6


>>> print 2<3

True

>>> print 2>3

False



>>> def absolute(x):

...    if x<0:

...       x=-x

...    return x

...

>>> absolute(5)

5

>>> absolute(-5)

5






>>> i=1

>>> while i!=10:

...    i=i+1

...    print i

...

2

3

4

5

6

7

8

9

10





>>> def get_next_target(page):

...    start_link = page.find('<a href=')

...    start_quote = page.find('"', start_link)

...    end_quote = page.find('"', start_quote + 1)

...    url = page[start_quote + 1:end_quote]

...    return url, end_quote

...

>>> url, endpos = get_next_target('good')

>>> print url

goo

b/c  the value is -1