TypeError: bad operand type for unary +: 'str'

def make_pizza(size,*toppings):
    """概述要制作的比萨"""
    print("\nMaking a "+str(size)+"-inch pizza with the following toppings:")

    for topping in toppings:
       # print(topping)
        print("- ",+ topping)

make_pizza(16,'pepperoni')
make_pizza(12,'mushrooms','green peeppers','extra cheese')

TypeError:一元运算符的错误操作数类型:'str'

解决方案

def make_pizza(size,*toppings):
    """概述要制作的比萨"""
    print("\nMaking a "+str(size)+"-inch pizza with the following toppings:")

    for topping in toppings:
       # print(topping)
        print("- "+ topping)

make_pizza(16,'pepperoni')
make_pizza(12,'mushrooms','green peeppers','extra cheese')

 

 

你可能感兴趣的:(TypeError: bad operand type for unary +: 'str')