【问题标题】:Python - what is "" meanPython - “”是什么意思
【发布时间】:2014-06-03 12:45:28
【问题描述】:

我正在使用 Python 并想知道如何编写一个要求 UN 和密码的程序。我正在使用“while 循环”的教程。

对于Command和Input1和Input2,为什么它们显示变量等于“”

他们显示:

name = raw_input("What is your UserName: ") 
password = raw_input("What is your Password: ") 
print "To lock your computer type lock."    
command = ""
input1 = ""
input2 = ""
while command != "lock":
    command = raw_input("What is your command: ") 
while input1 != name:
    input1 = raw_input("What is your username: ")



【问题讨论】:

    标签: python login passwords


    【解决方案1】:

    这只是意味着他们声明了两个字符串 input1 和 input2 并在接受用户输入之前确保它们是空字符串。

    【讨论】:

    • 这也像var input1; var input2;var input1; var input2;的JavaScript方式
    【解决方案2】:

    使用command="" 将创建一个名为command 的变量,它是一个空字符串。这经常使用,因此您可以清除变量并再次使用它。

    例如:

    >>> command = "hello world"
    >>> print command
    hello world
    >>> command = ""
    >>> print command
    
    >>> 
    

    【讨论】:

      【解决方案3】:

      他们在使用它们之前定义了变量,否则你会得到一个命令没有定义的错误,你的程序会失败。

      【讨论】:

        猜你喜欢
        • 2010-09-29
        • 1970-01-01
        • 1970-01-01
        • 2015-02-13
        • 1970-01-01
        • 2014-02-09
        • 2012-01-23
        • 2013-05-20
        • 2010-10-23
        相关资源
        最近更新 更多