有关print的一些问题
class Dog:def __init__(self, name, age):
self.name = name
self.age = age
def sit(self):
print(f'{self.name} is now sitting')
def roll_over(self):
print(f'{self.age} rolled over!')
my_dog = Dog('willie', 6)
print(f"my dog's name is {my_dog.name}.")
print(f"my dog is {my_dog.age} years old.")
print(my_dog.sit()) # 直接输出和用print有什么区别
我注释的,直接my_dog.sit()也可以正常运行,我想知道这两种方法有什么区别,谢谢各位 def foo():
print("我是 foo() 函数")
return "我是返回值"
print(foo())我是 foo() 函数
我是返回值
页:
[1]