一、模块初识:

Python有大量的模块,从而使得开发Python程序非常简洁。类库有包括三中:

  • Python内部提供的模块
  • 业内开源的模块
  • 程序员自己开发的模块

1、Python内部提供一个 sys 的模块,

① 其中的 sys.argv 用来捕获执行执行python脚本时传入的参数:

import sys

strings = sys.argv
print(strings)   # 所有参数 类型为列表
# ['start.py', 'hello', 'world']
print(strings[0])   # 脚本名本身
# start.py
print(strings[1])   # 第一个参数
# hello
print(strings[2])   # 第二个参数
# world
print(strings[-1])  # 倒数第一个参数
# world

$ python test.py helo world   执行脚本

② sys.stdin信息输入

读取的文件:

我越无所适从
越会事与愿违
在交错的时空
灵魂加速下坠
Here we are, here we are, here we are
lzl.txt

相关文章:

  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-07-23
  • 2021-07-13
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2021-07-01
  • 2021-08-19
  • 2021-12-09
  • 2021-04-26
  • 2022-02-01
  • 2021-06-27
  • 2021-04-13
相关资源
相似解决方案