1.创建模块:在IDLE中新建一个名叫fibo.py文件,编辑如下图:
第四,五章
按F5,然后可以在shell中导入这个模块了
如:

>>>import fibo
>>>fibo.fib(100)
1 1 2 3 5 8 13 21 34 55 89

2.输入输出
repr()和str():

>>>s='Hello,world.'
>>>str(s)
'Hello,world.'
>>>repr(s)
"'Hello,world.'"

3.文件读写
先建立一个f文件
>>>f=open('/tmp/workfile','w')
'/tmp/workfile’为文件名的字符串,
‘w’为文件使用方式的字符串
“r”为只读
‘w’为只写
‘a’为添加到文件结尾
‘r+’为可读可写
整体处理文件对象:

>>>with open('/tmp/workfile','r') as f:
... read_data=f.read()
>>>f.closed

相关文章:

  • 2021-07-13
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
猜你喜欢
  • 2021-06-19
  • 2021-06-29
  • 2021-11-01
  • 2021-07-28
  • 2021-05-15
  • 2021-09-11
  • 2022-12-23
相关资源
相似解决方案