码迷,mamicode.com
首页 > 编程语言 > 详细

python中print()函数的“,”与java中System.out.print()函数中的“+”

时间:2017-11-23 19:44:55      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:int()   函数   作用   int   之间   不同的   空格   class   hello   

python中的print()函数和java中的System.out.print()函数都有着打印字符串的功能。

python中:

print("hello,world!")

输出结果为:hello,world!

java中:

System.out.print("hello,world!");

输出结果为:hello,world!

我们可以看到,这两个函数的用法是一样的

 

print()函数还有这种用法:

print("1+1=",1+1)

输出结果为:1+1= 2

同样的,Java中也有:

System.out.print("1+1="+(1+1));

输出结果为:1+1=2

我们发现,在使用print()函数的时候,我们用了一个“,”将“1+1=”和1+1的结果连接起来了,这个“,”起着连接的作用。同时,在使用System.out.print()函数的时候,我们用了一个“+”将“1+1=”和1+1的结果连接起来了,这个“+”也是起着连接作用

我们再来看他们的输出结果,print()输出的是1+1= 2,“=”与“2”之间有一个空格,而System.out.print()输出的是1+1=2,“=”与“2”之间没有空格。这里我们发现python中的print()函数中的“,”不仅起着连接字符串的作用,而且还表示一个空格

 

总结:

  1.python中的print()函数的作用和java中的System.out.print()函数的作用是一样的

  2.print()函数中“,”和System.out.print()函数中“+”都有着连接字符串的作用

  3.print()函数中“,”还表示一个空格

  4.不同的语言都有着很多的相似点,不同的语言又有着不同的新特性

 

python中print()函数的“,”与java中System.out.print()函数中的“+”

标签:int()   函数   作用   int   之间   不同的   空格   class   hello   

原文地址:http://www.cnblogs.com/0796blogs/p/7885642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!