ajeef
V2EX  ›  Python

比 Python ,语法更简短的编程语言,有吗?可以是新语言或小众语言,对,仅仅是比简短(排它性)

By ajeef at 2017 年 7 月 5 日 · 11852 次点击

VB

Module MainFrm Sub Main() System.Console.WriteLine("Hello, World!") End Sub End Module

C

#include <stdio.h> int main() { printf("Hello, World!"); return 0; } Swift 1 print("Hello, World!")

Go

package main

import "fmt"

func main() { fmt.Print("Hello, World!") }

BATCH

@echo off echo Hello, World! pause


Java

public class HelloWorld { public static void main(String args[]) { System.out.println( "Hello, World!" ); } }


C++

#include <iostream> using namespace std; int main() { cout<<"Hello, World!"<<flush; return 0; }


C#

namespace HelloWorld { class Program { static void Main(string[] args) { System.Console.Write("Hello, World!"); } } }

PHP

echo "Hello, World!";

JavaScript

console.log("Hello, World!")

Python 3

print("Hello, World!")

LaTeX

\documentclass{article}

\begin{document} Hello, World!

\end{document}


Mathematica 方法一:基于 Wolfram 底层语言(进入表达式界面使用)

Cell["Hello, World!"]

方法二:直接使用数学输出函数

CellPrint[Cell["Hello, World!"]]

Ruby

def hello()
return "Hello , World"
end

易语言

调试输出( 1,“ Hello , World ”)


Kotlin

fun main(args: Array<string>) { println("Hello, world!") }

77 条回复  •  2017-07-07 12:24:51 +08:00
cbiqih
   1
cbiqih  
   2017 年 7 月 5 日
Dart
void main() {
print('Hello world');
}
wellsc
   2
wellsc  
   2017 年 7 月 5 日 via Android
elixir
def world do
IO.puts "Hello World"
end
102400
   3
102400  
   2017 年 7 月 5 日
论简短 Ruby 不把 Python 爆出翔?
SuperMild
   4
SuperMild  
   2017 年 7 月 5 日
语言本身,ruby 比 python 更灵活、丰富、有条理、简短,但是第三方库比不过 python。
102400
   5
102400  
   2017 年 7 月 5 日
@SuperMild Ruby 在早年的成长期确实斗不过 Py,现在论语言特性和性能毫不逊色 Python
oott123
   6
oott123  
   2017 年 7 月 5 日
ruby 难道不是
puts "hello world"
直接比 python 短了一个字符好么~
fogisland
   7
fogisland  
   2017 年 7 月 5 日   ❤️ 3
@oott123 我也刚想这么说。能故意写这么复杂也是不容易,那个 return 简直耀眼。
Kilerd
   8
Kilerd  
   2017 年 7 月 5 日 via iPhone
rust
println!("hello wirld")
ch3rub1m
   9
ch3rub1m  
   2017 年 7 月 5 日 via iPhone
ruby 明明还可以更短
p 'Hello World'
ch3rub1m
   10
ch3rub1m  
   2017 年 7 月 5 日 via iPhone
ruby 明明还可以更短

p 'Hello World'
zhujinliang
   11
zhujinliang  
   2017 年 7 月 5 日 via iPhone   ❤️ 5
卧槽,PHP 啊

Hello World

搞定
XadillaX
   12
XadillaX  
   2017 年 7 月 5 日   ❤️ 1
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

没看错,我上面的就是代码。
hsmocc
   13
hsmocc  
   2017 年 7 月 5 日 via iPhone   ❤️ 1
有病,得治
F281M6Dh8DXpD1g2
   14
F281M6Dh8DXpD1g2  
   2017 年 7 月 5 日 via iPhone   ❤️ 1
ruby 那个简直 233
XhstormR
   15
XhstormR  
   2017 年 7 月 5 日
fun main(args: Array<String>) = println("Hello, world!")
DiamondbacK
   16
DiamondbacK  
   2017 年 7 月 5 日
PowerShell
'Hello World!'
wellsc
   17
wellsc  
   2017 年 7 月 5 日 via iPad
HTML
Hello world!
v2beta
   18
v2beta  
   2017 年 7 月 5 日 via Android
Python IDLE
'Hello, World!'
bombless
   19
bombless  
   2017 年 7 月 5 日
噗,PHP 最短没毛病
lrxiao
   20
lrxiao  
   2017 年 7 月 5 日
听说过 golf 吗..听说过各种专为 golf 的语言吗
...
虽然 Hw 不是个 golf 好问题
https://codegolf.stackexchange.com/questions/55422/hello-world
g00001
   21
g00001  
   2017 年 7 月 5 日
只是控制台输出一句话就不写了,用 aardio 就写几句代码可以搞定一个完整的窗口程序,不要任何外部的第三方库,如果再多写几句代码那就是很漂亮的窗口
jyf
   22
jyf  
   2017 年 7 月 5 日
Forth

." hello, world"
Chingim
   23
Chingim  
   2017 年 7 月 5 日
ruby 能写成这样, 连我这个门外汉都看不过去了
hihihihihi
   24
hihihihihi  
   2017 年 7 月 5 日
printf("WTF!!!")
unsec
   25
unsec  
   2017 年 7 月 5 日
PHP 最短,不需要什么 echo 或者 print 或者 p,甚至不用引号:
Hello World
noli
   26
noli  
   2017 年 7 月 5 日 via iPhone
楼主理解的编程美感就是为了短而短?抑或只是无聊带个节奏?
xyjtou
   27
xyjtou  
   2017 年 7 月 5 日
Python 不能再短了,直接输出,连 print 都可以不用吖

>>> 'hello world'
'hello world'
initialdp
   28
initialdp  
   2017 年 7 月 5 日
Lua...

去年我们将内部一个业务模块从 Python 改用 Lua 重写,Lua 比 Python 简短多了。
AngelCriss
   29
AngelCriss  
   2017 年 7 月 5 日 via Android
(display “ hello racket ”)
mingyun
   30
mingyun  
   2017 年 7 月 5 日
@unsec 不会报错?
lululau
   31
lululau  
   2017 年 7 月 5 日
@xyjtou

➜ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 'hello world'
'hello world'


➜ ipython
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
Type "copyright", "credits" or "license" for more information.

IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: 'hello world'
Out[1]: 'hello world'

还是 Ruby 短:

➜ irb
2.4.0 :001 > 'hello world'
=> "hello world"

➜ pry
[1] pry(main)> 'hello world'
=> "hello world"
cheneydog
   32
cheneydog  
   2017 年 7 月 5 日
groovy
println "hello world"
wwhc
   33
wwhc  
   2017 年 7 月 5 日
perl -e 'print "Hello World\n"'
4641585
   34
4641585  
   2017 年 7 月 5 日
$ node
> "hello world"
'hello world'
lululau
   35
lululau  
   2017 年 7 月 5 日
@wwhc perl -le 'print "Hello World"'
lululau
   36
lululau  
   2017 年 7 月 5 日
还是 Shell 最短:

➜ brew install hello
➜ hello
Hello, world!
est
   37
est  
   2017 年 7 月 5 日   ❤️ 1
比 helloworld 没意思啊。要比就比从某个客户端证书 https 的 json API 里读取一个逗号分隔的字符串切成数组然后做快排。
paledream
   38
paledream  
   2017 年 7 月 5 日   ❤️ 3
看了这贴想学 PHP 啊。。
agostop
   39
agostop  
   2017 年 7 月 5 日
perl

say "hello,world";
Maic
   40
Maic  
   2017 年 7 月 5 日
为啥没人说 HTML,就直接 Hello World 就搞定了
lsido
   41
lsido  
   2017 年 7 月 6 日 via Android
@Maic 我正想说
Ringokun
   42
Ringokun  
   2017 年 7 月 6 日
对啊,Ruby 不应该是 p 'Hello world' 吗
NoAnyLove
   43
NoAnyLove  
   2017 年 7 月 6 日
简单我不知道,不过如果要是比短的话,应该 perl 更出色吧
johnlui
   44
johnlui  
   2017 年 7 月 6 日 via Android
Ruby 的 return 真的亮瞎了我…虽然我是 PHP 程序员…
bazingaterry
   45
bazingaterry  
   2017 年 7 月 6 日 via iPhone   ❤️ 2
我以后设计一门语言的时候,一定要内置一个打印 Hello World 的函数!
Lucups
   46
Lucups  
   2017 年 7 月 6 日   ❤️ 1
显然 PHP 不是最短。。。

毕竟如果代码多一点的话,所有的变量名都要比人家多一个字符。。。
flyingghost
   47
flyingghost  
   2017 年 7 月 6 日
1,很不明白 lz 要求一句 helloworld 最短干嘛。要比短也得比一个较复杂的方法。例如 @est #37.
2,很明显 lz 并没有理解“排他性”的含义并且误用了。
3,我刚刚实现了一门语言内置 HelloWorld,只要一句 `pH`就可以了,才 2 个字符。lz 要不要学?
lrxiao
   48
lrxiao  
   2017 年 7 月 6 日
@flyingghost 没错 比如 Stuck (
waruqi
   49
waruqi  
   2017 年 7 月 6 日
lua
geelaw
   50
geelaw  
   2017 年 7 月 6 日 via Android
PowerShell:
'Hello, world!'
ibcker
   51
ibcker  
   2017 年 7 月 6 日
班门弄斧

ruby

p "hello world"
cxbig
   52
cxbig  
   2017 年 7 月 6 日
还记得见过一个个人签名是:
“写得一手好 Hello World ”
Trim21
   53
Trim21  
   2017 年 7 月 6 日
@est 这个方法不错
msg7086
   54
msg7086  
   2017 年 7 月 6 日
我也是被楼主的 ruby 代码亮瞎来的。
mahone3297
   55
mahone3297  
   2017 年 7 月 6 日
@g00001 感觉 aardio 和 vb 非常像,比起来, 如何?
hjc4869
   56
hjc4869  
   2017 年 7 月 6 日 via Android
C 没那么长
main(){printf("Hello World");}
就好
texange
   57
texange  
   2017 年 7 月 6 日
~ ❯ irb
2.4.0 :001 > puts "hello world"
hello world
=> nil
araraloren
   58
araraloren  
   2017 年 7 月 6 日
@oott123 就是,楼主要是“找事”,对比好歹严格点


@msg7086 我是看到那代码才回复的,虽然我不会 ruby,但我也知道绝对不是那么写的。。
northisland
   59
northisland  
   2017 年 7 月 6 日 via iPhone
汇编
zhujinliang
   60
zhujinliang  
   2017 年 7 月 6 日 via iPhone   ❤️ 1
都别争了
有个叫 ls 的语言,代码长度可以为零,即一个字符也不需要,而且操作系统自带
只不过文件名必须是 “ Hello World ”
xuqd
   61
xuqd  
   2017 年 7 月 6 日
object Main extends App {
println("hello word")
}
yidinghe
   62
yidinghe  
PRO
   2017 年 7 月 6 日 via Android
我记得汇编语言每行都很短,而且看起来非常整齐,充满美感。
Tink
   63
Tink  
   2017 年 7 月 6 日
shell
free9fw
   64
free9fw  
   2017 年 7 月 6 日
swift
print("hello world")
scriptB0y
   65
scriptB0y  
   2017 年 7 月 6 日
这帖子毫无意义,英语的冗余在 50%,Python 也有冗余,任何人类使用的编程语言都需要冗余,编程语言追求的是表述清楚,首先要让人类能看懂
g00001
   66
g00001  
   2017 年 7 月 6 日   ❤️ 1
@mahone3297 对,都可以方便的写桌面软件( 不过 aardio 也可以用来写网站 ),但是 aardio 写的软件不像 VB 那样依赖额外安装运行环境,语法跟 VB 也不是一个风格,例如上面发的那个 aardio 窗口程序,用 VB 写就会是这个样子:

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3135
ClientLeft = 60
ClientTop = 405
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3135
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 2640
TabIndex = 1
Top = 1080
Width = 1215
End
Begin VB.TextBox Text1
Height = 375
Left = 600
TabIndex = 0
Text = "Text1"
Top = 1080
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim retValue As Long
retValue = MsgBox("hello " + Form1.Text1.Text, 1, "hello")
End Sub
natforum
   67
natforum  
   2017 年 7 月 6 日
elixir

iex> "Hello"
"Hello"
zhouyang
   68
zhouyang  
   2017 年 7 月 6 日
短有什么好。。。女孩子都喜欢长的
ysr1023
   69
ysr1023  
   2017 年 7 月 6 日   ❤️ 2
Ruby

p 'Hello World'

话说这种帖子真没有营养
LukeXuan
   70
LukeXuan  
   2017 年 7 月 6 日
txt

Hello World

理论上来说不会有更短的了
maxco292
   71
maxco292  
   2017 年 7 月 6 日
这是在比 helloworld 长短吗,最起码搞个一些常见算法数据结构(譬如快排)的代码
coolcfan
   72
coolcfan  
   2017 年 7 月 6 日
看到 Ruby 那条就想说明明可以 p "Hello World",看到楼上已经说过了。
senghoo
   73
senghoo  
   2017 年 7 月 6 日
go 可以不 import fmt 包。可以直接用 println..

package main
func main() { println("abc") }
longbye0
   74
longbye0  
   2017 年 7 月 6 日
Scala
wobuhuicode
   75
wobuhuicode  
   2017 年 7 月 6 日
写完 OC 之后感觉什么都短!
glasslion
   76
glasslion  
   2017 年 7 月 6 日
@LukeXuan 自创一门语言,源码文件为空,则输出 hello world

:doge: :doge: :doge:
loveminds
   77
loveminds  
   2017 年 7 月 7 日
erlang
io:format("Hello World!")
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
© 2026 V2EX · 190ms · 3.9.8.5