cynorr

Learn what I touched.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Input and print

Some useful ways to enter and print

Input:

Differences between input( ) and raw_input( ):

String str we input:

  • By input( ): str can't contain blank space
  • By raw_input( ): str can contain blank space, so we can extract some items by using str.split(' ')
    Example1:Enter some integers separated by a ( or some ) space .
    '''
    import string
    str = raw_input() #str = '45 12 32 65'
    chars = str.split(' ')
    ints = []
    for i in chars:
    ints.append(int(i)) # string to int function: int(str)
    print ints #[45,12,32,65]
    '''

print:

  • Stand style of print integer:
    Example : print '%d * %d = %-3d"%(i,j,result) #%-3d Align right 3 characters.
  • Several items in a common raw:
    print item1,item2, # a , followed items
posted on 2014-10-24 21:26  cynorr  阅读(99)  评论(0)    收藏  举报