美文网首页
笨办法学Python ex13

笨办法学Python ex13

作者: Joemini | 来源:发表于2016-12-10 21:26 被阅读0次

    参数, 解包, 变量


    • 输入:
    # -- coding: utf-8 --
    
    from sys import argv
    # import 语句,这是将 Python 的功能模块加入你自己脚本的方法
    
    script, first, second, third = argv
    # 将参数变量“argv”解包
    
    print "The script is called:", script
    print "Your first variable is:", first
    print "Your second variable is:", second
    print "Your third variable is:", third
    
    • 运行:


    在cmd输入打开这个py文件的同时,要输入3个参数才能正常运行


    附加题

    • 将 raw_input 和 argv 一起使用
    from sys import argv
    
    script, a, b = argv
    
    print "The script is called:", script
    print "The first variable is:", a
    print "The second variable is:", b
    
    y=raw_input("Please input your name\n>")
    print "Hello, my name is %s." % y
    

    相关文章

      网友评论

          本文标题:笨办法学Python ex13

          本文链接:https://www.haomeiwen.com/subject/mvyumttx.html