s = input("Enter your input:")
print([object, ...][, sep=' '][, end='endline_character_here'][, file=redirect_to_here])
print('hello', 'world', sep='%') # 输出 hello%world
print('hello', 'world', end='*') # 输出 hello world*,并且不换行
f = open(filename,mode)
f = open('a.txt','wb+')
f.write('I like apple!') # 报错
f.write(b'I like apple!') # 以bytes对象的形式进行读写
b1 = b'This is string'
b2 = bytes('This is string', 'UTF-8') # 必须指定编码格式
b = bytes('This is string', 'UTF-8')
print(b, b.decode(), sep='\n')
# 输出:
# b'This is string'
# This is string
for line in f: print(line, end='')
# 第一种方式:自己控制
for x in range(1, 11):
print(str(x).rjust(2), str(x*x).rjust(3), end=' ')
print(str(x*x*x).rjust(4))
# 第二种方式:str.format()
for x in range(1, 11):
print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x))
# 输出都是:
# 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
>>> print('We are the {} who say "{}!"'.format('knights', 'Ni'))
We are the knights who say "Ni!"
>>> print('{0} and {1}'.format('Kobe', 'James'))
Kobe and James
>>> print('{1} and {0}'.format('Kobe', 'James'))
James and Kobe
>>> print('The {thing} is {adj}.'.format(thing='flower', adj='beautiful'))
The flower is beautiful.
>>> import math
>>> print('The value of PI is {0:.3f}.'.format(math.pi))
The value of PI is 3.142.
>>> table = {'Jack':4127, 'Rose':4098, 'Peter':7678}
>>> for name, phone in table.items():
... print('{0:10} ==> {1:10d}'.format(name, phone))
...
Peter ==> 7678
Rose ==> 4098
Jack ==> 4127
table = {'Jack':4127, 'Rose':4098, 'Peter':7678}
print('Jack is {Jack}, Rose is {Rose}, Peter is {Peter}.'.format(**table))
# 输出:Jack is 4127, Rose is 4098, Peter is 7678.
import math
print('The value of PI is .3f.' %math.pi)
# 输出:The value of PI is 3.142.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有