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. wmsys.wm_concat结果长度限制的问题

    转:http://bbs.csdn.net/topics/360059765 使用wmsys.wm_concat多列合成一列遇到问题ORA-22813: 操作数值超出系统的限制 官方文档解释是总长度超 ...

  2. magent实现memcached集群的一个问题

    之前我们小组封装了一个memcached类库,里面有一个名为RemoveStartWith的方法可以根据起始字符串删除所有节点中负责键值规则的缓存项.它实现的原理就是通过stats命令获取每个节点的所 ...

  3. stdarg.h头文件源代码分析

    谈到C语言中可变参数函数的实现(参见C语言中可变参数函数实现原理),有一个头文件不得不谈,那就是stdarg.h 本文从minix源码中的stdarg.h头文件入手进行分析: #ifndef _STD ...

  4. 改变presentModalView大小

    rc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; rc.modalPresentationStyle = UIModalP ...

  5. centos7下安装nmon后,无法运行,提示 cannot execute binary file或/lib64/ld64.so.1不存在

    在centos 7.1上安装nmon后,从管网(http://nmon.sourceforge.net/pmwiki.php?n=Site.Download)下载tar包解压后,两台机器一台提示 ca ...

  6. Unity3D笔记 英保通九 创建数

    Unity中创建树:可以直接通过程序自动来创建树木还可以手动创建树木(本质上在我看来就是给程序自动创建的树动动”小手术“) 一.程序自动创建树木 3.1.层次视图中创建:一个平行光.摄像机.地.数并且 ...

  7. all hands meeting

    今天某导师联系我说:"There will be an allhand" 搞不懂allhand是啥意思……他口头跟我解释的是就是个茶话会性质的小会~ 我在网上查了一下,这个用法很少 ...

  8. Solve minGW g++ has stopped working 程序停止运行

    之前在机子装了个很早版本的MinGW,苦于不支持c++11,所以打算卸载掉安装个新版本的.可是网上找了很多版本装好后,编译成功,运行的时候总是弹出 *.exe has stopped working的 ...

  9. 从Spring到SpringBoot构建WEB MVC核心配置详解

    目录 理解Spring WEB MVC架构的演变 认识Spring WEB MVC 传统时代的Spring WEB MVC 新时代Spring WEB MVC SpringBoot简化WEB MVC开 ...

  10. FileStream实现多线程断点续传(已封装)

    处理文件分片 处理缺失的分片文件 合并分片文件 MD5验证文件 using System; using System.Collections.Generic; using System.IO; usi ...