python - 不理解这段代码的真假部分。我在此代码中的输入(所有整数)如何“为真”或“为假”?
问题描述
print("Please enter integers (then press enter key twice to show you're done):")
s = input() #whatever you're inputting after the print
first = True #What does this mean???
while s != "": #What does this mean???
lst = s.split() #split all your inputs into a list
for x in lst:
if first: #If its in ur lst?
maxV = int(x) #then the max value will be that input as an integer
first = False #What does this mean?
else:
if maxV < int(x):
maxV = int(x)
s= input()
print(maxV)
我对这段代码中的 first=True 和 first=False 感到困惑,将变量设置为 true 或 false 是什么意思?也对 while s != "": 的含义感到困惑。对不起,我是一个完整的初学者,如果有人可以帮助我,将永远感激不尽
解决方案
我真的不知道这是什么编程语言,但通过基本知识我可以告诉你这些东西的含义。我希望它有帮助:
print("Please enter integers (then press enter key twice to show you're done):")
s = input() #Here s becomes your input
first = True #Here you set first as a boolean which can have the state true or false. In this example it gets the value True assigned
while s != "": #While repeats a certain process and in this example it keeps this process going while s isn't empty
lst = s.split() #splits all your inputs into a list <- you got that right
for x in lst:
if first: #It checks if first is true. If it is true it keeps going with the code right after the if
maxV = int(x) #then the max value will be that input as an integer
first = False #this sets a new value to first. which is false in this case
else:
if maxV < int(x):
maxV = int(x)
s= input()
print(maxV)
另外你说你不明白!=
. !=
是一样==
的,但恰恰相反。意思是不平等。因此,如果你说这样的话1 == 1
是真的,因为 1 等于 1。如果你说1 != 2
这是真的,因为 1与2 不同。
推荐阅读
- android - Android Kivy JsonStore data.json does not persist across upgrades
- django - Using query to match object and then get all objects associated via foreignkey
- python - Floating Object is not iterable
- python - 将数据框列从字符串转换为数字列表
- node.js - 尝试使用 vanilla JS 发送请求 GET 来表达时,响应为空
- javascript - 如何更改在画布上呈现的单个对象的不透明度?
- c++ - 重载的虚拟行为是否定义良好?
- mongodb - Mongodb使用$lookup查找给定_id属于哪个对象(外域是一个数组)
- javascript - 如何使用条件语句检查 javascript 中构造函数的值?
- php - 使用数组中的数据插入多个 MYSQLI