2018.2.21 Python 初学习

折腾了一天,一直在用CMD学习Python写Hello World。偶然间发现可以用Pycharm。也算是给后面想学习的人提个醒,方便省事许多。

format()使用方法。

age = 20
name = 'Swaroop'
print('{0} was {1} years old when he wrote this book'.format(name, age))
print('Why is {0} playing with that python?'.format(name))

# 对于浮点数 '0.333' 保留小数点(.)后三位
print('{0:.3f}'.format(1.0/3))
# 使用下划线填充文本, 并保持文字处于中间位置
# 使用 (^) 定义 '___hello___'字符串长度为 11
print('{0:_^11}'.format('hello'))
# 基于关键词输出 'Swaroop wrote A Byte of Python'
print('{name} wrote {book}'.format(name='Swaroop', book='A Byte of Python'))

输出:
0.333
___hello___
Swaroop wrote A Byte of Python

占位符替换内容
%d 整数
%f 浮点数
%s 字符串
%x 十六进制整数

 

指定以空格结尾,end=’‘

 

 continue 语句,跳过当前循环块中的剩余语句,并开始下一次迭代。

 

 

 

原文地址:https://www.cnblogs.com/wongsh/p/8456792.html