2019独角兽企业重金招聘Python工程师标准>>>

吐槽下,python2 官方文档的print资料好少啊,看的别人博客才知道咋用╮(╯_╰)╭

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sysprint(sys.version)#输入与输出#str()与repr()
for x in range(1, 11):print repr(x).rjust(2), repr(x*x).rjust(3),#逗号代表不换行print repr(x*x*x).rjust(4)#格式化输出
for x in range(1, 11):print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)print 'We are the {} who say "{}!"'.format('knights', 'Ni')
print '{1} and {0}'.format('spam', 'eggs')
print 'This {food} is {adjective}.'.format(food='spam', adjective='absolutely horrible')
print 'The story of {0}, {1}, and {other}.'.format('Bill', 'Manfred', other='Georg')import math
#保留三位小数点
print 'The value of PI is approximately {0:.3f}.'.format(math.pi)table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
for name, phone in table.items():print '{0:10} ==> {1:10d}'.format(name, phone)print 'Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table)#old style, 语法类似sprintf
print 'The value of PI is approximately %5.3f.' % math.pi
print 'x = %d, y = %d' % (3, 4)# #文件的读写
# f = open('/tmp/workfile', 'r+')
# print f
#
# #f.write('This is a test\n')
#
# f.read()
#
# f.readline()
#
# f.readlines()
#
# for line in f:
# print line
#
# #write something other than string
# value = ('the answer', 42)
# s = str(value)
# f.write(s)
#
# f = open('/tmp/workfile', 'r+')
# f.write('0123456789abcdef')
# f.seek(5) # Go to the 6th byte in the file
# f.read(1)
# f.seek(-3, 2) # Go to the 3rd byte before the end
# f.read(1)
#
# f.close()
# f.read()
#
# with open('/tmp/workfile', 'r') as f:
# read_data = f.read()
#
# f.closedif __name__ == "__main__":a = 1b = 2

Reference

  1. http://docs.pythontab.com/python/python2.7/inputoutput.html#tut-formatting

转载于:https://my.oschina.net/Jerrymingzj/blog/803838

Python2 之 print函数示例相关推荐

  1. Python2.7 Print函数

    Print函数的各种用法 一.基础用法 1.print语句可以向屏幕上输出指定的文字. 例如: print 'Hello World!' 2.print语句也可以跟上多个字符串,用逗号",& ...

  2. Python2中print函数用法

    使用print输出各型的 字符串 整数 浮点数 出度及精度控制 strHello = 'Hello Python' print strHello #输出结果:Hello Python #直接出字符串 ...

  3. python2.7 print函数

    1.输出十六进制,十进制,八进制 >>> hex = 0xff >>> print 'hex=%x,dec=%d,oct=%o' %(hex,hex,hex) he ...

  4. Python学习记录——1.print()函数与变量

    文章目录 1.print()函数 2.变量和赋值 3.总结 4.练习 4.1 打印皮卡丘 4.2 听见无脸男的声音 1.print()函数 示例如下: import time print ('在'+t ...

  5. 【python】print函数的用法示例与讲解

    python学习 本文以python3为核心 文章目录 python学习 一.有用的知识点 1.print 输出不换行 2.f"{}"的用法 二.格式规范 1.字符串输出格式 2. ...

  6. python2中可以使用print()函数吗_Python3中的 print 函数有哪些用法?

    自从python3更新以后,大家对函数的热情再一次高涨起来,好多小伙伴问小编,3之后函数的使用有没有什么改变?今天小编就这个问题,跟大家说一说,感兴趣的小伙伴可以来看下了哦~ 关于print函数的用法 ...

  7. python中延时函数_python中实现延时回调普通函数示例代码

    python中实现延时回调普通函数示例代码 这篇文章主要给大家介绍了关于python中实现延时回调普通函数的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的 ...

  8. python中print的用法_Python中print函数简单使用总结

    Python中print函数简单使用总结 print函数是Python的入门,每一个学习python的人都绕不开这个函数,下面介绍一下这个函数的用法. 打开电脑,选择python软件,下面选择pyth ...

  9. python语言print函数_Python 的 print 函数

    Python 2.x 系列已经停止维护了, python  3.x 系列正在成为主流,尽管有些项目还是python2.x 的,之后写Python 代码为了保持兼容性,还是尽量和Python 3 标准保 ...

最新文章

  1. 在linux下部署安装Tomact并运行javaWeb工程
  2. 中美首份8000字长文解析全球热点脑机接口(重磅干货)
  3. 胶囊网络全新升级!引入自注意力机制的Efficient-CapsNet
  4. 编写你的第一个 Django 应用,第 1 部分
  5. Win7下如何挂载NFS共享目录
  6. 【嵌入式设计】嵌入式低功耗设计
  7. 花 30 万招聘的高级程序员,真的值吗?
  8. ABP动态生成WebAPI
  9. 微软在线测试之lucky string,有关斐波那契的题目都在此了
  10. 升级Xcode8后需要添加的一些权限
  11. 亮风台AR眼镜震撼发布 HiAR 产品全面升级
  12. Linux meset
  13. USB 大容量存储设备的开发
  14. 阿里应届程序员年薪25W,我酸了,你们呢
  15. 2021-05-10
  16. Google 辟谣,Android 和 Chrome OS 不合并 - Andromeda
  17. 数据结构学习——RBT(红黑树)以及实现Map和Set
  18. CMake I 设置编译器标志
  19. 高速—HDMI布线规则
  20. 物联网,已经到来的产业“风口”

热门文章

  1. Node.JS 学习路线图
  2. Delphi第三方组件安装DCU.PAS.DPK.BPL.ActiveX控件
  3. 通用的启动参数获取getopt
  4. Linux 3.10 新特性
  5. Hadoop系列之七:分布式文件系统HDFS(2)
  6. petshop 4.0的数据持久层
  7. 连接远程mysql遇到的问题及解决方法
  8. (常用API)正则表达式的概念和作用
  9. 权限操作-springSecurity概述及快速入门步骤分析
  10. 字节输出流_OutputStream类FileOutputStream类介绍