输入
- 等待用户输入:
#!/usr/bin/python3
input("\n\n按下 enter 键后退出。")
输出
- print输出,print 默认输出是换行的
- 如果要实现不换行需要在变量末尾加上 end=""
#!/usr/bin/python3
x="a"
y="b"
# 换行输出
print( x )
print( y )
print('---------')
# 不换行输出
print( x, end=" " )
print( y, end=" " )
print()
导入模块
在 python 用 import 或者 from...import 来导入相应的模块。
- 将整个模块(somemodule)导入,格式为: import somemodule
- 从某个模块中导入某个函数,格式为: from somemodule import somefunction
- 从某个模块中导入多个函数,格式为: from somemodule import firstfunc, secondfunc, thirdfunc
- 将某个模块中的全部函数导入,格式为: from somemodule import *