码迷,mamicode.com
首页 > 编程语言 > 详细

2018.2.21 Python 初学习

时间:2018-02-21 17:43:53      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:table   wro   swa   占位符   his   字符串长度   学习   this   world   

折腾了一天,一直在用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 初学习

标签:table   wro   swa   占位符   his   字符串长度   学习   this   world   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!