python3(一)print

print('test', '怎么自动建了这么多目录', 'aaaaaaa')  #test 怎么自动建了这么多目录 aaaaaaa
注释#
# ---------------------------------------
a = 100
if a >= 0:
    print(a) #100
else:
    print(-a)
# ---------------------------------------
转义
print('I\'m ok.')  # I'm ok.
r''表示''内部的字符串默认不转义
print(r'\\\t\\')  # \\\t\\
 换行
print('ab \nvvcc')
# ab
# vvcc
'''...'''的格式表示多行内容
print('''line1 
line2 
line3''')
#line1
#line2
#line3
#使用 sep 和 end 关键字参数分别设置 seperator 和 end :
print('a', 'b', 'c', sep='-')
# Prints a-b-c
print('Hello', end=' ')
print('World')
# Prints Hello World
 
#输出到文件
with open('file.txt', 'w') as f:
    print('Hello', file=f)
# Prints Hello to file.txt
#格式化字符串使用 str.format():
#python
print('Hello {}, your balance is {}.'.format('Adam', 42.50))
# Prints Hello Adam, your balance is 42.5
#or  f-string(在 Python 3.6+):
name = 'Adam'
balance = 42.50
print(f'Hello {name}, your balance is {balance}.')
# Prints Hello Adam, your balance is 42.5

 

# 占位符
c = 'Hi, %s, you have $%d.' % ('Michael', 1000000)
print(c)  # Hi, Michael, you have $1000000.
# 占位符    替换内容
# %d    整数
# %f    浮点数
# %s    字符串
# %x    十六进制整数

 


posted @ 2019-09-18 16:34  ~清风煮酒~  阅读(138)  评论(0编辑  收藏  举报