一个 print("Hello world!") 能玩出几个花样
本帖最后由 asky533 于 2022-10-6 20:20 编辑一个 print("Hello world!") 能玩出几个花样
普普通通式
print("Hello world!")
变量式
text = "Hello world!"
print(text)
函数式
def sayhello():
print("Hello world!")
sayhello()
模块式
a.py:
def main():
print("Hello world!")
b.py:
import a
a.main()
参数式
def sayhello(x):
print(x)
sayhello("Hello world!")
类式
class IO:
def out(self,text):
print(text)
stdio = IO()
stdio.out('Hello, World!')
Tensorflow 式
import tensorflow as tf
hello = tf.constant("Hello world!")
sess = tf.Session()
h = sess.run(hello)
print(h.decode())
无 print() 式
#myhello.py
import sys
from time import time
from os import system
def _output(string):
try:
for i in string:
sys.stdout.write(i)
sys.stdout.flush()
sys.stdout.flush()
return 0
except:
return 1
class my_io(object):
def __init__(self):
self.string = '\0'
def output(self):
return _output(self.string)
def main():
global text, mio, errno
errno = 0
text = 'Hello World!'
mio = my_io()
mio.string = text
if mio.output():
errno = 1
return 1
return 0
if __name__ == '__main__':
st = time()
main()
en = time()
exit_output = my_io()
exit_output.string = f"\n--------------------------------\nProcess exited after {round(en - st, 3)} seconds with return value {errno}\n请按回车继续..."
exit_output.output()
sys.stdin.readline()
sys.exit(errno)
ASCII 编码 + 解包式
print(*)*100+len('aaaaaaa a aaa a a a aaa'.split(' '))*10+len('aa a aaaaaaaa aaaaaaaa a aa aaaaaaaaa a aaaa aaaaaaaaaaa'.split(' '))) for i in range(12)], sep = '')
彩蛋式
import __hello__
瞧瞧,一个 Hello world 能玩出多少花样,我们在写程序时也不能一根筋的去写
牢记:条条大路通罗马! {:10_256:} class IO:
def out(self,text):
print(text)
stdio = IO()
stdio.out('Hello, World!') 本帖最后由 zhangjinxuan 于 2022-10-6 10:07 编辑
#myhello.py
import sys
from time import time
from os import system
def _output(string):
try:
for i in string:
sys.stdout.write(i)
sys.stdout.flush()
sys.stdout.flush()
return 0
except:
return 1
class my_io(object):
def __init__(self):
self.string = '\0'
def output(self):
return _output(self.string)
def main():
global text, mio, errno
errno = 0
text = 'Hello World!'
mio = my_io()
mio.string = text
if mio.output():
errno = 1
return 1
return 0
if __name__ == '__main__':
st = time()
main()
en = time()
exit_output = my_io()
exit_output.string = f"\n--------------------------------\nProcess exited after {round(en - st, 3)} seconds with return value {errno}\n请按回车继续..."
exit_output.output()
sys.stdin.readline()
sys.exit(errno)
{:10_279:}【无print!】 >>> print(*)*100+len('aaaaaaa a aaa a a a aaa'.split(' '))*10+len('aa a aaaaaaaa aaaaaaaa a aa aaaaaaaaa a aaaa aaaaaaaaaaa'.split(' '))) for i in range(12)], sep = '')
Hello world!
{:10_279:} tommyyu 发表于 2022-10-6 10:06
WTF? tommyyu 发表于 2022-10-6 10:06
ASCII码是吧 无print式我服了 zhangjinxuan 发表于 2022-10-6 09:56
【无print!】
厉害{:10_256:}
页:
[1]