不同的笔记本输出可以通过以下几种方法来解决:
import platform
def get_notebook_output():
notebook = platform.platform()
if 'Mac' in notebook:
print("Mac 笔记本输出")
elif 'Windows' in notebook:
print("Windows 笔记本输出")
elif 'Linux' in notebook:
print("Linux 笔记本输出")
else:
print("其他笔记本输出")
get_notebook_output()
import platform
def get_notebook_output():
notebook = platform.platform()
notebook_output = {
'Mac': "Mac 笔记本输出",
'Windows': "Windows 笔记本输出",
'Linux': "Linux 笔记本输出"
}
output = notebook_output.get(notebook, "其他笔记本输出")
print(output)
get_notebook_output()
import platform
class Notebook:
def output(self):
print("其他笔记本输出")
class Mac(Notebook):
def output(self):
print("Mac 笔记本输出")
class Windows(Notebook):
def output(self):
print("Windows 笔记本输出")
class Linux(Notebook):
def output(self):
print("Linux 笔记本输出")
def get_notebook_output():
notebook = platform.platform()
if 'Mac' in notebook:
notebook_instance = Mac()
elif 'Windows' in notebook:
notebook_instance = Windows()
elif 'Linux' in notebook:
notebook_instance = Linux()
else:
notebook_instance = Notebook()
notebook_instance.output()
get_notebook_output()
下一篇:不同的并发范式有何区别?