python-基础入门-2

这里介绍两个,相当于c中的scanf函数

第一个raw_input

1 age=raw_input("how old are you ")
2 print "you are %d old." % age

当遇到raw_input 时,程序的运行会中止,弹出括号里的字符串,你输入的值将会赋给前面的变量

第二个argv

1 from sys import argv
2 
3 script, name , tall ,weight  = argv
4 
5 print "the script is called:", script
6 print "your name variable is:", name
7 print "your tall variable is:", tall
8 print "your weight variable is:", weight

from ****import***是调用库,以后会经常碰到

argv保存着你在运行变量时输入的参数,将其中的东西给拿出来。

第一个是script,它是这个脚本的名字,随后输入的三个变量分别赋给name,tall,weight。

在运行时,参数跟在脚本名后就行

原文地址:https://www.cnblogs.com/hongren/p/7143556.html