• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一个C++初学者
博客园    首页    新随笔    联系   管理    订阅  订阅

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

 

 

 

posted @ 2018-02-21 17:19  一个C++初学者  阅读(250)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3