Hello, world!
Posted feedbacks - Python
オーソドックスに。
1 | print "Hello, world!"
|
1 | print ''.join(map(chr, [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]))
|
フォーマット文字列内の参照文字列をリストのインデックス番号で指定。
1 2 | words = ['hello', 'world']
print '%(0)s, %(1)s!' % dict([w == 'hello' and (`i`, w.capitalize()) or (`i`, w) for i, w in enumerate(words)])
|
高階関数としてのstr.__add__の利用方法。文字列を+で連結するので実行速度は遅い。
1 2 3 4 | words = ['hello', 'world']
words[0] = ''.join(['H', words[0][1:]])
words[1] = ''.join([', ', words[1], '!'])
print reduce(str.__add__, words)
|
import __hello__ と書きたかったけど、お題と文字がちょっと違う。。 print, sys.stdout.write が出てるので、YAWTDI: バイトコード版
1 2 3 4 5 6 7 8 9 10 11 12 13 | import new
from opcode import opmap
consts = [None, 'Hello, world!']
bytecode = ''.join(map(chr, [
opmap['LOAD_CONST'], consts.index('Hello, world!'), 0,
opmap['PRINT_ITEM'],
opmap['PRINT_NEWLINE'],
opmap['LOAD_CONST'], consts.index(None), 0,
opmap['RETURN_VALUE']
]))
exec new.code( 0, 0, 1, 1, bytecode, tuple(consts), (), (), "", "hello", 0, "\x00\x01")
|


にしお
#3358()
Rating0/0=0.00
[ reply ]