python3------print 打印输出

 

# 1、打印字符串
print('hello world!')

输出结果:

hello world!

#2、打印中文字符串
print ('世界,你好!')

输出结果:

 
世界,你好!

# 3、打印变量
a=10
print(a)

输出结果:

 
10

# 4、打印自定义函数值
def add2(x,y):
    return [x+2,y+2]
print (add2(0,0))

输出结果:

 
[2, 2]

# 5、python每执行一次print语句时,自动在打印内容末尾加入一个换行符
print('hello world!',)
print ('世界,你好!')

 

 输出结果:
hello world!
世界,你好!

# 6、# 如下print后添加end='',相当于执行print语句时,在打印内容后加一个空格,默认end='\n'换行
print('hello world!',end=' ')
print('世界,你好!')

输出结果:

 
hello world! 世界,你好!

# 7、两个字符串拼接打印 用"+"
print('hello world!'+'世界,你好!')

输出结果:

 
hello world!世界,你好!

 

# 8、两个字符串换行打印 用空格加转义字符\nprint('hello world! \n世界,你好!')

输出结果:

 
hello world! 
世界,你好!

#9、利用制表符\t控制打印内容水平间隔,目的对齐,\t 8个字符的宽度为一块,每8个字符后面都有一个制表点
print('number \tSquare \tCube')
for i in range(1,11):
    print(i,'\t',i**2,'\t',i**3)

输出结果

 
number 	Square 	Cube
1 	 1 	 1
2 	 4 	 8
3 	 9 	 27
4 	 16 	 64
5 	 25 	 125
6 	 36 	 216
7 	 49 	 343
8 	 64 	 512
9 	 81 	 729
10 	 100 	 1000

 

# 10、格式化字符串输出 %s字符串格式输出,%d整数格式输出 %f浮点型格式输出 %e科学计数法 %g自动浮点计数法
print('I love %s.'%'marry')
print('She is %d years old.' %18)
print('Her height is %fm.' %1.63)
print('Her height is %.2fm.' %1.634)

输出结果:

 
I love marry.
She is 18 years old.
Her height is 1.630000m.
Her height is 1.63m.

#11、format()方法形如
print('She is {} years old.Her height is {}.'.format(18,1.63))

输出结果:
She is 18 years old.Her height is 1.63.
posted on 2018-04-07 20:38  木子~  阅读(3834)  评论(0编辑  收藏  举报