215330 发表于 2017-12-25 15:59:26

代码报错



def print_hello(name, sex):
    sex_dict = {1: u'先生', 2: u'女士'}
    print 'hello %s %s, welcome to python world!' %(name, sex_dict.get(sex, u'先生'))
print_hello('tanggu', 1)

老铁看看我这段代码执行不了呢,一直报错,无效语句。

BngThea 发表于 2017-12-25 16:09:28

你如果用的python3.x版本,那么 print是一个函数,要这样用
def print_hello(name, sex):
    sex_dict = {1: u'先生', 2: u'女士'}
    print ('hello %s %s, welcome to python world!' %(name, sex_dict.get(sex, u'先生')))
print_hello('tanggu', 1)
页: [1]
查看完整版本: 代码报错