python输入与输出165
1 s = 'Hello,Runoob' 2 3 print(s) 4 5 str(s) 6 print(s) 7 8 print(repr(s)) 9 10 print(1/7) 11 print(str(1/7)) 12 print(repr(1/7)) 13 14 print('repr()的用法') 15 x = 10*3.25 16 y = 200*200 17 s = 'x的值为:'+str(x)+',y的值为:'+str(y) 18 print(s) 19 20 s = 'x的值为:'+repr(x)+',y的值为:'+repr(y) 21 print(s) 22 23 24 print('repr()可以转义特殊字符') 25 hello = 'hello ,runoob\n' 26 print(hello)#hello ,runoob 27 28 hellos = repr(hello) 29 print(hellos)#'hello ,runoob\n' 30 31 ts = ('Google','Runoob') 32 repr((x,y,ts)) 33 print(type(ts)) 34 print(x,y,ts)#32.5 40000 ('Google', 'Runoob') 35 36 print('输出平方根与立方根') 37 for x in range(1,11): 38 # print(x.rjust(2),x*x,x*x*x),,AttributeError: 'int' object has no attribute 'rjust'' 39 # print(x.rjust(2),x*x,x*x*x) 40 print(str(x).rjust(2),str(x*x).rjust(5),str(x*x*x).rjust(10)) 41 42 43 '方式二' 44 for x in range(1,11): 45 # print('{0}{1}{2}'.format(x, x ** 2, x ** 3)) 46 #2d即两个空格 47 print('{0:2d}{1:5d}{2:6d}'.format(x,x**2,x**3)) 48 49 50 51 print('zfill()即补足空格') 52 for x in range(1,11): 53 # print(x.rjust(2),x*x,x*x*x),,AttributeError: 'int' object has no attribute 'rjust'' 54 # print(x.rjust(2),x*x,x*x*x) 55 print(str(x).zfill(2),str(x*x).zfill(5),str(x*x*x).zfill(10)) 56 57 58 59 'format()的用法' 60 print('{0}和{1}'.format('Google','Runoob')) 61 print('{1}和{0}'.format('Google','Runoob')) 62 print('{name}网址:{site}'.format(name = '菜鸟教程',site = 'www.site.com')) 63 #点列表 Google, Runoob, 和 Taobao。 64 print('站点列表{0},{1},{other}'.format('Google','Runoob',other = 'Taobao')) 65 66 '!a,!s,!r格式化某个值之前对其进行转换' 67 import math 68 #常量 PI 的值近似为: 3.141592653589793。 69 print('常量PI的近似值为{}'.format(math.pi)) 70 print(type(math.pi)) 71 72 #使用!r或者!s后输出的值都是float类型的? 73 pi2=math.pi 74 print('常量PI的近似值为:{!r}'.format(pi2)) 75 print(type(pi2)) 76 77 pi3=math.pi 78 print('常量PI的近似值为:{!s}'.format(pi3)) 79 print(type(pi3)) 80 81 #常量 PI 的值近似为 3.142。 82 print('常量PI的近似值为{0:.3f}'.format(math.pi)) 83 print('常量PI的近似值为{0:.2f},{1:.3f}'.format(math.pi,math.pi))#常量PI的近似值为3.14,3.142 84 85 # Runoob ==> 2 86 # Taobao ==> 3 87 # Google ==> 1 88 #int类型的直接为:10d,如果是str类型的为:5,没有d 89 table = {'Runoob':2,'Taobao':3,'Google':1} 90 print(type(table)) 91 for name,num in table.items(): 92 print('{0:5}===>{1:10d}'.format(name,num)) 93 print(type(num)) 94 print(type(name)) 95 96 #Runoob: 2; Google: 1; Taobao: 3(不会这是什么?)============================================================================== 97 table = {'Google': 1, 'Runoob': 2, 'Taobao': 3} 98 print('Runoob: {0[Runoob]:d}; Google: {0[Google]:d}; Taobao: {0[Taobao]:d}'.format(table)) 99 100 101 #其中的5是什么意思呢? 102 import math 103 print('常量 PI 的值近似为:%5.3f。' % math.pi) 104 105 'input()从标准输入读入一行文本,这里的标准输入就是指的键盘' 106 # 请输入:菜鸟教程 107 # 你输入的内容是: 菜鸟教程 108 # str = input('请输入:') 109 # print('您输入的内容是:',str) 110 111 112 113 f = open('E:\\foo.txt','a') 114 f.write('Python是一个非常好的语言。\n是的,的确非常好wb+,a!!') 115 f.close() 116 117 print('写入并读取打印出来') 118 #这部分是写入文件中内容 119 f = open('E:\\foo.txt','w') 120 f.write('Python是一个非常好的语言。\n是的,的确非常好w!!') 121 #这部分是打开并读取文件内容 122 f = open('E:\\foo.txt','r')#没有这句是打印不出来内容的 123 str = f.read() 124 print(str) 125 126 print('readline()的用法') 127 print('到这里了') 128 f = open('E:\\foo.txt','r') 129 str1 = f.readline() 130 print(str1) 131 f.close() 132 133 print('readlines()的用法') 134 f = open('E:\\foo.txt','r') 135 str2 = f.readlines() 136 print(str2) 137 f.close() 138 139 print('迭代读取每行') 140 f = open('E:\\foo.txt','r') 141 for line in f: 142 print(line,end='') 143 144 print('读取写入的字数') 145 f = open('E:\\foo.txt','w') 146 num = f.write('Python是一个非常好的语言。\n是的,的确非常好w!!') 147 print(num) 148 149 print("向 foo1.txt 文件中写入‘'www.runoob.com', 14’") 150 f = open('E\\foo1.txt','w') 151 value = 'www.runoob.com' 152 s = str(value) 153 f.write(s,14) 154 155 156 print("向 foo1.txt 文件中写入‘'www.runoob.com', 14’") 157 f2 = open('E:\\foo1.txt','w+') 158 value = 'www.runoob.com' 159 s = str(value) 160 f2.write(s) 161 162 f2 = open('E:\\foo1.txt','r') 163 s = f2.read() 164 # s = str(f2) 165 print(s)
转载于:https://www.cnblogs.com/jpr-ok/p/9230498.html
python输入与输出165相关推荐
- python3中文手册-Python 输入和输出
Python 输入和输出 在前面几个章节中,我们其实已经接触了 Python 的输入输出的功能.本章节我们将具体介绍 Python 的输入输出. 输出格式美化 Python两种输出值的方式: 表达式语 ...
- [转载] Python输入,输出,Python导入
参考链接: Python输入,输出和导入 In this tutorial we will cover the basics of Python Input/Output and also how t ...
- Python输入,输出,Python导入
In this tutorial we will cover the basics of Python Input/Output and also how to import a module in ...
- Python 输入和输出
输出 用print加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print 'hello, world' print语句也 ...
- python输入输出-python输入与输出
python输出 python3中的输出 python3中的输出使用函数print(),示例如下: >>> print('hello kitty') print()也可接受多个参数, ...
- python输入和输出的区别_python2和python3的输入和输出区别介绍
Python3 输入和输出 输出格式美化 Python两种输出值的方式: 表达式语句和 print() 函数. 第三种方式是使用文件对象的 write() 方法,标准输出文件可以用 sys.stdou ...
- python中倒着输出输入值_十五、深入Python输入和输出
「@Author:By Runsen」 在很多时候,你会想要让你的程序与用户(可能是你自己)交互.你会从用户那里得到输入,然后打印一些结果.我们可以使用input和print语句来完成这些功能. in ...
- 萌新学python(输入与输出)
输出函数 print("Hello World") 编程中除了中文其他的请全部用英文输入法 上边的程序代表输出字符串Hello World 其中print()是输出函数,()里面的 ...
- [Python]输入与输出
1. 读取命令行选项 Python启动时,命令行选项放置在列表sys.argv中.例如: import sys if len(sys.argv) != 3:sys.stderr.write(" ...
最新文章
- 【Java挠头】Java异常、捕获、处理、throw、throws等绝妙剖析
- python-IO多路复用,select模块
- deepin安装node,npm
- [译] APT分析报告:03.OpBlueRaven揭露APT组织Fin7/Carbanak(上)Tirion恶意软件
- Flex 序列化自定义类 解决 sharedObject 保存自定义对象
- 算法基础:图的相关算法知识笔记
- JQuery $作用
- Unable to establish loopback connection异常解决
- 杭电4502吉哥系列故事——临时工计划
- git常用命令与常见问题解决办法
- Chisel3 - Tutorial - Parity
- 容器的主要目的是什么,Wise2C睿云智合的实战
- 数据库日志系统之删库跑路后的亡羊补牢
- POJ 4047 Garden 线段树 区间更新
- OpenCV图像处理专栏六 | 来自何凯明博士的暗通道去雾算法(CVPR 2009最佳论文)
- IOM计算机组成原理,计算机组成原理-实验1静态随机存储器实验
- .bat文件闪退,原因及解决
- Mybatis联表查询:多对多(注解实现)
- spark-sql总结
- 单片机编程软件很简单(八),Keil单片机编程软件辅助功能讲解
热门文章
- linux的网络命令整理 更新中
- 20145234黄斐《Java程序设计》第五周
- Delphi 原生ADO(二)
- PHP开发移动端接口(增强版)
- Java的类装载器(Class Loader)和命名空间(NameSpace)
- C语言利用循环判断大月小月,对大月和小月进行判断
- Flask搭建二进制音频传送接口
- ENAS加载自己的数据集之路
- virtualbox+vagrant学习-2(command cli)-16-vagrant snapshot命令
- 一款优秀的JavaScript框架—AngularJS