I wanna check if user typed string is True or False, my program creates a new variable when the user type data.create {name} {value}
and this variable is stored in a list called "data", with some script it gets the name and the value and can print using type $data.{name}
.
To not make any problems or make the program more hard, it formats the string, so think that I created a data: data.create hllw Hello World
and then I typed it on the console: type $data.hllw
, the first thing that is executed is the formater because if it detect an $data
in the string, it separates by a dot and get the name and check if the variable exists on the list. So type $data.hllw
turns into type Hello World
Now, I want to make an if
command, that do this: if $data.hllw == Hello World
(If hllw var is "Hello World" it return True, else return False), but I don't know do this, I thinked that eval() can help, but no: if eval(args):
(args = the arguments of if).
If I try:
if args:
print('True!')
else:
print('False!')
it returns always "True!" :(
The only scenario where your if
statement will return False
is when you test a empty string. You do not need a special function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.