sys.argv
import sys
argv = sys.argv
argv[0]是py文件名,argv[1]及以后是跟着的参数
python test.py hello pyorz 1
# argv[0]="test.py"
# argv[1]="hello"
# argv[2]="pyorz"
# argv[3]="1"
注意,参数空格隔开,传进去都是作为字符串(比如最后的这个1)
a = int(argv[3])# 可以通过这种方式进行转换
input()
age = input("your ages:")
print(age)
print('根据两点坐标计算直线斜率k,截距b:')
while True:
line = input()
if line == '\n': break
x1, y1, x2, y2 = (float(x) for x in line.split())
k = (y2 - y1) / (x2 - x1)
b = y1 - k * x1
print('斜率:{},截距:{}'.format(k, b))
sys.stdin
import sys
# line1 = sys.stdin.readline() # 包含换行符"\n"
line1 = sys.stdin.readline().strip('\n') # 去掉换行符"\n"
line2 = input() # 不包含换行符"\n"
print(len(line1), len(line2))
import sys
while True:
line = sys.stdin.readline() # 一次只读一行
if line is '\n': # 如果是空行就停止
break
a = line.split()
print(int(a[0]) + int(a[1])) # 否则回显,再回去读下一行
import sys
list1 = []
while True:
line = sys.stdin.readline()
if line is '\n':
break
a = line.split()
for i in a:
list1.append(int(i))
print(list1)
import sys
sys.stdout.write('根据两点坐标计算直线斜率k,截距b:\n')
for line in sys.stdin:
if line == '\n': break
x1, y1, x2, y2 = (float(x) for x in line.split())
k = (y2 - y1) / (x2 - x1)
b = y1 - k * x1
sys.stdout.write('斜率:{},截距:{}\n'.format(k, b))
sys.exit(arg=0) 用于退出 Python。0 或者 None 表示正常退出,其他值表示异常。
import sys
In [61]:sys.platform
Out[62]:'win32'