开发者

Using if-condition to check filename

I'm doing a real silly mistake in Python but unable to find what it is

I'm doing something like this in python

filename="file1"
if name == 'file1'
    print 1

I'开发者_开发知识库m getting an invalid syntax error


You are missing a colon

filename="file1"
if name == 'file1':
    print 1


You need to put a colon at the end of the if statment

filename="file1"
if name == 'file1':
    print 1


what is name?? did you define it elsewhere?? I assume its "filename" instead, so

filename="file1"
if filename == 'file1':
    print 1

if "name" is defined, then the problem is indeed the ":" at the end of "if" line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜