首页 > 编程语言 > 详细

2018.2.21 Python 初学习

时间:2018-02-21 17:38:18      阅读:239      评论:0      收藏:0      [点我收藏+]

折腾了一天,一直在用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 语句,跳过当前循环块中的剩余语句,并开始下一次迭代。

 

 

 

2018.2.21 Python 初学习

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!