3

python学习笔记_4_open_close_def_module_import_sys


使用python的open()来打开文件

  1. #!/usr/bin/python
  2. handle = open('hi.py','r') #默认就是r是只读;还有w是写文件;
  3. fof x in handle:
  4.    print x,
  5. handle.close()


python的def函数

  1. >>> def name(x):
  2. ...    return (x + x)
  3. ...
  4. >>> name(1)
  5. 2
  6. >>> name(2)
  7. 4
  8. >>> name(1212)
  9. 2424
  10. >>> name('a')
  11. 'aa'
  12. >>> name('b')
  13. 'bb'
  14. >>> name('abab')
  15. 'abababab'
  16. >>> name('python ')
  17. 'python python

python的模块

  1. #!/usr/bin/python
  2. import sys
  3. sys.stdout.write('hello world!\n')

我猜~这些文章你可能也感兴趣

总共有3个留言:

  1. 365hope on 四 22nd, 2009 - 21:39

    忙碌起来应该是好事,无限支持老大的革命事业!
    顺利、顺心!



    回复:谢谢您的好意 :)

  2. 雅丹地貌 on 四 23rd, 2009 - 11:20

    虽然看不懂 不过还是支持下



    回复:3Q3Q

  3. 纸黄金网 on 四 26th, 2009 - 10:55

    学而时习之

给我留言:

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word