功能不会改变全局变量

时间:2017-02-03 19:58:57

标签: python

我正在尝试使用python创建一个程序,但我无法修改全局变量。我正在运行python 2.7。当我运行下面的代码并在python中运行one()时,它不会像操作那样将operationOne从0更改为1。关于如何在这个函数中创建东西的任何想法都会修改全局变量吗?

operationOne = 0
operationTwo = 0
operationUsed = False
def one():
    global operationOne
    global operationTwo
    global operationUsed
    if operationUsed == False:
        operationOne = 1
    if operationUsed == True:
        operationTwo = 1

2 个答案:

答案 0 :(得分:0)

您正在将operatorUsedoperationUsed进行比较。

当我运行此代码时,我收到错误operatorUsed未定义。

修复它,它应该按预期工作。

答案 1 :(得分:0)

将其更改为:

<section class="one">
  <div class="container">
    <h1 class="title4 part1">WELCOME TO MY</h1>
    <h1 class="title4 part2">PORTFOLIO</h1>
  </div>
</section>

.one {position:relative;}
.container {
  position:absolute;
  /*control the postition of the container div by left=,bottom=,top=,right=*/
}

写它就像对我有用。

相关问题