Python 3为变量分配2个值

时间:2015-11-03 23:34:22

标签: python variables python-3.x

import subprocess
import time

Python = True

firefoxbrowser = 'firefox', 'firefox browser'

FirefoxLink = 'C:/Program Files (x86)/Mozilla Firefox/firefox.exe'

while Python is True:
    print("What program do you want to open?")
    program = ''
    launch = ''
    program = input().lower()

    if program = firefoxbrowser:
        launch = FirefoxLink #launch will be used for later commands
        print("launching Firefox!")

    #reserved for later work

当我在命令行中键入OR firefox浏览器或firefox时,我正在尝试创建一个启动Firefox的程序。 我想为firefoxbrowser分配2个值,用于'firefox'和'firefox browser'。然而,使用“'firefox','firefox browser'”或使用“'firefox'和'firefox browser'”会以多种方式破坏程序。 如何为一个变量实现2个值?

2 个答案:

答案 0 :(得分:2)

您需要做的就是改变

ThingSchema

    while (result.next()) {

        Student student = new Student(); //declare a new student

        student.setFristName(result.getString(1));

        student.setLastName(result.getString(2));       

        Studentlist.add(student);


    }

if program = firefoxbrowser: 是一个元组。检查if program in firefoxbrowser: 是否是其中一个元素。

答案 1 :(得分:1)

尝试创建这样的元组:

firefox_browser = ("firefox", "firefox browser")

然后您应该可以使用索引来访问它:

firefox_browser[0]
firefox_browser[1]

您还可以通过元组解包访问项目:

ffb1, ffb2 = firefox_browser