" "或者单引号' '包围,例如:
"Hello World"
"Number is 198"
'Pyhon教程:http://c.biancheng.net/python/'
print("字符串内容")
或者print('字符串内容')
字符串要放在小括号( )中传递给 print,让 print 把字符串显示到屏幕上,这种写法在 Python 中被称为函数(Function)。
print("Hello World!") #输出英文
print("Number is 198") #输出数字
print("Pyhon教程:http://c.biancheng.net/python/") #输出中文
在 IDLE 下的演示效果:
print(
"Hello World!"
"Number is 198"
"http://c.biancheng.net/python/"
);
print("Hello World!" "Python is great!" "Number is 198.")
print(
"Hello World!\n"
"Number is 198\n"
"http://c.biancheng.net/python/"
);
注意,同一个 print 函数的字符串之间不会自动换行,加上\n才能看到换行效果。;,用来表示一个语句的结束。但是 Python 比较灵活,它不要求语句使用分号结尾;当然也可以使用分号,但并没有实质的作用(除非同一行有更多的代码),而且这种做法也不是 Python 推荐的。
print(198);
print("Hello World!"); print("Python is good!");
print("Pyhon教程:http://c.biancheng.net/python/");
运行结果:
198
Hello World!
Python is good!
Pyhon教程:http://c.biancheng.net/python/
( ),但是以前的 Python 2.x 版本可以省略小括号,也即是写成下面的样子:
print 198 print "Hello World!"; #末尾也可以加上分号 print "Pyhon教程:http://c.biancheng.net/python/"我建议大家加上小括号,这样写比较容易理解,而且兼容性好。
print( 100 )
print( 65 )
print( 100 + 12 )
print( 8 * (4 + 6) )
print("100 + 12")
运行结果是100 + 12,而不是 112。
print( 100 12 95 );
print(
80
26
205
);
#include <stdio.h>
int main()
{
puts("http://c.biancheng.net/");
return 0;
}
public class HelloJava {
public static void main(String[] args) {
System.out.println("http://c.biancheng.net/");
}
}
print("http://c.biancheng.net/")
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有