【问题标题】:python variable passing in functions [duplicate]传入函数的python变量[重复]
【发布时间】:2013-03-28 22:01:13
【问题描述】:

我的代码的 sn-p:

def determinewelltype(currentuwi,welltype):
    if current uwi in vertuwis:
        welltype = "Vertical"

currentuwi = "1aa010109306w400"
welltype = "UNKNOWN"
determinewelltype(currentuwi,welltype)
print currentuwi,welltype

在我的代码的另一部分,我构建了一个名为 vertuwis 的列表,它由许多字符串组成。

这个 sn-p 正在尝试确定 currentuwi 是否在 vertuwis 列表中。如果是,井型应该是垂直的。

我知道给定的 currentuwi 在我的列表中,但是当我在最后一行代码中打印井类型时,井类型是 UNKNOWN,这意味着我的代码不起作用。

我哪里出错了?

【问题讨论】:

标签: python list function


【解决方案1】:

这更正了代码中的错误:

vertuwis = ['a', 'b', 'c']

def determinewelltype(currentuwi,welltype):
    if currentuwi in vertuwis:
        welltype = "Vertical"
    return welltype

currentuwi = "a"
welltype = "UNKNOWN"
welltype = determinewelltype(currentuwi,welltype)
print currentuwi,welltype   # prints out: a Vertical

【讨论】:

    猜你喜欢
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 2023-01-24
    • 1970-01-01
    • 2015-03-21
    • 1970-01-01
    • 2017-10-24
    相关资源
    最近更新 更多