s = 'Hello,Runoob'

 print(s)

 str(s)
print(s) print(repr(s)) print(1/7)
print(str(1/7))
print(repr(1/7)) print('repr()的用法')
x = 10*3.25
y = 200*200
s = 'x的值为:'+str(x)+',y的值为:'+str(y)
print(s) s = 'x的值为:'+repr(x)+',y的值为:'+repr(y)
print(s) print('repr()可以转义特殊字符')
hello = 'hello ,runoob\n'
print(hello)#hello ,runoob hellos = repr(hello)
print(hellos)#'hello ,runoob\n' ts = ('Google','Runoob')
repr((x,y,ts))
print(type(ts))
print(x,y,ts)#32.5 40000 ('Google', 'Runoob') print('输出平方根与立方根')
for x in range(1,11):
# print(x.rjust(2),x*x,x*x*x),,AttributeError: 'int' object has no attribute 'rjust''
# print(x.rjust(2),x*x,x*x*x)
print(str(x).rjust(2),str(x*x).rjust(5),str(x*x*x).rjust(10)) '方式二'
for x in range(1,11):
# print('{0}{1}{2}'.format(x, x ** 2, x ** 3))
#2d即两个空格
print('{0:2d}{1:5d}{2:6d}'.format(x,x**2,x**3)) print('zfill()即补足空格')
for x in range(1,11):
# print(x.rjust(2),x*x,x*x*x),,AttributeError: 'int' object has no attribute 'rjust''
# print(x.rjust(2),x*x,x*x*x)
print(str(x).zfill(2),str(x*x).zfill(5),str(x*x*x).zfill(10)) 'format()的用法'
print('{0}和{1}'.format('Google','Runoob'))
print('{1}和{0}'.format('Google','Runoob'))
print('{name}网址:{site}'.format(name = '菜鸟教程',site = 'www.site.com'))
#点列表 Google, Runoob, 和 Taobao。
print('站点列表{0},{1},{other}'.format('Google','Runoob',other = 'Taobao')) '!a,!s,!r格式化某个值之前对其进行转换'
import math
#常量 PI 的值近似为: 3.141592653589793。
print('常量PI的近似值为{}'.format(math.pi))
print(type(math.pi)) #使用!r或者!s后输出的值都是float类型的?
pi2=math.pi
print('常量PI的近似值为:{!r}'.format(pi2))
print(type(pi2)) pi3=math.pi
print('常量PI的近似值为:{!s}'.format(pi3))
print(type(pi3)) #常量 PI 的值近似为 3.142。
print('常量PI的近似值为{0:.3f}'.format(math.pi))
print('常量PI的近似值为{0:.2f},{1:.3f}'.format(math.pi,math.pi))#常量PI的近似值为3.14,3.142 # Runoob ==> 2
# Taobao ==> 3
# Google ==> 1
#int类型的直接为:10d,如果是str类型的为:5,没有d
table = {'Runoob':2,'Taobao':3,'Google':1}
print(type(table))
for name,num in table.items():
print('{0:5}===>{1:10d}'.format(name,num))
print(type(num))
print(type(name)) #Runoob: 2; Google: 1; Taobao: 3(不会这是什么?)==============================================================================
table = {'Google': 1, 'Runoob': 2, 'Taobao': 3}
print('Runoob: {0[Runoob]:d}; Google: {0[Google]:d}; Taobao: {0[Taobao]:d}'.format(table)) #其中的5是什么意思呢?
import math
print('常量 PI 的值近似为:%5.3f。' % math.pi) 'input()从标准输入读入一行文本,这里的标准输入就是指的键盘'
# 请输入:菜鸟教程
# 你输入的内容是: 菜鸟教程
# str = input('请输入:')
# print('您输入的内容是:',str) f = open('E:\\foo.txt','a')
f.write('Python是一个非常好的语言。\n是的,的确非常好wb+,a!!')
f.close() print('写入并读取打印出来')
#这部分是写入文件中内容
f = open('E:\\foo.txt','w')
f.write('Python是一个非常好的语言。\n是的,的确非常好w!!')
#这部分是打开并读取文件内容
f = open('E:\\foo.txt','r')#没有这句是打印不出来内容的
str = f.read()
print(str) print('readline()的用法')
print('到这里了')
f = open('E:\\foo.txt','r')
str1 = f.readline()
print(str1)
f.close() print('readlines()的用法')
f = open('E:\\foo.txt','r')
str2 = f.readlines()
print(str2)
f.close() print('迭代读取每行')
f = open('E:\\foo.txt','r')
for line in f:
print(line,end='') print('读取写入的字数')
f = open('E:\\foo.txt','w')
num = f.write('Python是一个非常好的语言。\n是的,的确非常好w!!')
print(num) print("向 foo1.txt 文件中写入‘'www.runoob.com', 14’")
f = open('E\\foo1.txt','w')
value = 'www.runoob.com'
s = str(value)
f.write(s,14) print("向 foo1.txt 文件中写入‘'www.runoob.com', 14’")
f2 = open('E:\\foo1.txt','w+')
value = 'www.runoob.com'
s = str(value)
f2.write(s) f2 = open('E:\\foo1.txt','r')
s = f2.read()
# s = str(f2)
print(s)

python输入与输出165的更多相关文章

  1. Python - 输入和输出 - 第十七天

    Python 输入和输出 在前面几个章节中,我们其实已经接触了 Python 的输入输出的功能.本章节我们将具体介绍 Python 的输入输出. 输出格式美化 Python两种输出值的方式: 表达式语 ...

  2. python 输入和输出

    到目前为止我们遇到过两种输出值的方法: 表达式语句和print语句. (第三个方式是使用文件对象的write()方法: 标准输出文件可以引用 sys.stdout.详细内容参见库参考手册. Pytho ...

  3. Python输入和输出

    在很多时候,你会想要让你的程序与用户(可能是你自己)交互.你会从用户那里得到输入,然后打印一些结果.我们可以分别使用raw_input和print语句来完成这些功能.对于输出,你也可以使用多种多样的s ...

  4. Python输入与输出

    输出 print函数 语法: print(self, *args, sep=' ', end='\n', file=None) print函数是python中最常见的一个函数.用于将内容打印输出. p ...

  5. Python 输入与输出

    Python2版本 raw_input raw_input("输入提示"),会把输入的内容当做字符串返回 input 会把用户输入的内容当做代码来处理,可以理解为 raw_inpu ...

  6. Ulipad Python输入先后输出问题

    print "Enter a interger"number=input() 在菜单栏 python-----设置参数----在Parameters:那栏加个参数 -u , 就可以 ...

  7. python输入一个\输出2个\问题

    在Python里面,如果\后面不是一个合法的转移字符,那么,Python会打印两个\,换句话说,Python将\也当成普通字符看待,而不是转义符的标志: >>>S = 'C:\py\ ...

  8. Python学习--02输入和输出

    命令行输入 x = input("Please input x:") y = raw_input("Please input x:") 使用input和raw_ ...

  9. Python 基础【第三篇】输入和输出

    这里我们创建一个python(pytest)脚本用于学习测试(以后都为这个文件,不多做解释喽),这个文件必须要有执行权限的哈 1.创建pytest并赋予执行权限 [root@fengyuba_serv ...

随机推荐

  1. CF 166E Tetrahedron

    E. Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. .net的XML对象序列化VS WCF中xml序列化问题

    整理一下 .net 对象序列化注意事项: 1. 字段:必须是 public类型 2.属性:只读或者只写的属性不被序列化,只有 可读可写并且赋值的才可以 序列化: Someclass obj = new ...

  3. 问题记录,如何解决confluence的office预览的时候的乱码问题

    在新的服务器(ubuntu16.04)上安装confluence,预览office的附件的时候,发现中文无法正确显示 在网上搜了一下,搜到一篇官方的文档,是关于这个问题的 问题原因: 在服务器上没有安 ...

  4. .net C#中页面之间传值传参的六种方法

    1.QueryString是一种非常简单的传值方式,他可以将传送的值显示在浏览器的地址栏中.如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法.但是对于传递数组或对象的话,就不能 ...

  5. SQL Server2008 R2 安装失败后的解决办法

    当你第一次安装SQL Server2005,SQL Server2008,SQL Server2012失败后,第二次重新安装一般还是容易安装失败,原因就是你没有完全卸载,还存留残留文件和注册表. 我安 ...

  6. VSCode集成TypeScript编译

    先安装github客户端和nodeJS客户端吧,直接去官网下载,nodeJS客户端安装完就集成了npm; 查看是否成功: git version  node -v npm-v 安装TypeScript ...

  7. 51单片机之IIC通信原理及软件仿真

    关于IIC我觉这个博客里面说的已经够清楚了 如下图所示的写操作的时序图: 其实像这种通信协议的要求是很精确的,一点点不对都可能导致在实际工程中无法读取数据.我就是被一个应答位耽误了好久,还好最后被我发 ...

  8. CentOS环境下jdk安装部署

    1.准备jdk安装文件: 这里我使用的是 jdk-7u79-linux-x64.tar.gz 2.在 /usr/local 目录下创建 sotfware目录,并上传JDK文件: 解压文件并修改文件夹为 ...

  9. myeclipse乱码/GBK只支持中文

    Windows>>Pereferences>>General>Editors>>Spelling>>Encoding选项下选择other,然后输入 ...

  10. 高盛为什么认为中国AI领域将超越美国?

    不久前,高盛发布的名为<中国在人工智能领域崛起>的研究报告,报告中,高盛认为中国已经成为AI领域的主要竞争者,中国政府建设“智慧型经济”和“智慧社会”的目标将有可能推动中国未来GDP的增长 ...