python传递参数

1、脚本

# -*- coding: utf-8 -*-

from sys import argv
script, first,second = argv #将命令中输入的参数解包后传递给左边

age = int(input("age:"))  #强行将输入的字符串转换为整形

number = float(input('>')) # (1)强行将输入的字符串转换为浮点型 (2)'>'键盘输入的提示符 
print ("The script is called:", script) #一次传递一个参数
print ("Your first variable is:", first)
print ("I just want to say,that",first)
print ("the sentences is that:", first,second)  #一次传递两个参数
print ("I just want to say,that%s, her age is %s" %(first,second))  #一次传递两个命令参数的另一种方法
print ("Your age is:%d" %age)
print ("her age is %d,I just want to say,that" %age,first) #一次传递两个参数(1个参数来自命令,一个参数来自键盘输入的一种方法)

print ("I just want to say that %s,her age is %d" %(first,age)) #一次传递两个参数(1个参数来自命令,一个参数来自键盘输入的另一种方法)

print ("the number is %f" %number)

 2、执行结果

原文地址:https://www.cnblogs.com/merry-0131/p/8427922.html