【问题标题】:How to use with statement correctly?如何正确使用 with 语句?
【发布时间】:2022-06-13 12:42:14
【问题描述】:

请帮我理解如何使用这个语句并举个例子(没有open()方法)

def say_hello(text:str):
 return print(text)
with say_hello("Hello") as hello:
 hello

【问题讨论】:

    标签: python python-3.x with-statement python-3.9 python-3.10


    【解决方案1】:

    标准约定应该是

    hello = say_hello("Hello")
    # your code here
    hello.close()
    

    【讨论】:

      猜你喜欢
      • 2014-12-13
      • 2020-09-04
      • 1970-01-01
      • 2020-09-01
      • 2015-09-15
      • 1970-01-01
      • 2015-08-26
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多