Python:简单if:语句表示语法无效

时间:2017-05-09 15:49:41

标签: python if-statement syntax-error

我继续在第2行获取无效语法,我不确定我做错了什么。

ffi = require "ffi"
-- sample structure, yours will differ
ffi.cdef [[
    typedef struct Node_s { struct Node_s *next; int value; } Node;
]]

-- in your case you will get a pointer from C, which you can then
-- ffi.cast( "Node*", ptr )
-- after that, you can access the fields (ptr.next, ptr.value etc.)
-- we'll just use some dummy sample data here:
do
    local p = ffi.new( "Node" )
    local q = ffi.new( "Node" )
    p.next = q
    p.value, p.next.value = 23, 42
    ptr = tonumber( tostring( p ):match( ": (0x%x*)" ) )
end

data = ffi.cast( "Node*", ptr )
print( "first value:", data.value )
--> first value:    23
print( "second value:", data.next.value )
--> second value:   42
print( "third value:", data.next.next.value )
--> Segmentation fault   [so be just as careful as you're in C(++)!]

我也尝试过:

operator = input("Would you like to +, -, *, or /?:")
if (operator != "+"):
  print ("Unknown operator!")

但是它总是打印出“未知操作员!”

老实说,我很擅长编码,任何帮助都会受到赞赏!谢谢!

0 个答案:

没有答案