python的输入输出方式
2014-10-13 16:35
399 查看
使用代码显示:
>>> x=20
>>> x
20
>>> print x
20
>>> print "hello world"
hello world
>>> y = 30
>>> z = x + y
>>> print z
50
>>> str1 = raw_input("input str:")
input str:123dkfiasdnfg
>>> print str1
123dkfiasdnfg
>>> n = len(str1)
>>> print n
13
>>> print(format(12.23434),'6.3f')
('12.23434', '6.3f')
>>> print(format(12.23434),'6.3f'))
SyntaxError: invalid syntax
>>> print(format(12.23434,'6.3f'))
12.234
>>> print(format(12.23434,'6.9f'))
12.234340000
>>> print(format(12.23434,'6.0f'))
12
>>> print(format(12.23434,'9.2f'))
12.23
>>> print(format(12.23434,'3.3f'))
12.234
>>> print(format(0.3456,'.2%'))
34.56%
>>> print(format(0.3456,'3.1%'))
34.6%
>>> print(format(0.3456,'6.1%'))
34.6%
>>> help(raw_input)
Help on built-in function raw_input in module __builtin__:
raw_input(...)
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
>>> str2 = raw_input()
woshihaoren
>>> print str2
woshihaoren
>>> type(str2)
<type 'str'>
>>> age = raw_input(your age:)
SyntaxError: invalid syntax
>>> age = raw_input("your age:")
your age:19
>>> type(age)
<type 'str'>
>>> age = age+1
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
age = age+1
TypeError: cannot concatenate 'str' and 'int' objects
>>> age = int(age)
>>> age = age +1
>>> age
20
>>> f1 = float('12.35')
>>> type(f1)
<type 'float'>
>>> print f1
12.35
>>> weight = float(raw_input("please input your weight:"))
please input your weight:23.14
>>> type(weight)
<type 'float'>
>>> print x,f1
20 12.35
>>> x=20
>>> x
20
>>> print x
20
>>> print "hello world"
hello world
>>> y = 30
>>> z = x + y
>>> print z
50
>>> str1 = raw_input("input str:")
input str:123dkfiasdnfg
>>> print str1
123dkfiasdnfg
>>> n = len(str1)
>>> print n
13
>>> print(format(12.23434),'6.3f')
('12.23434', '6.3f')
>>> print(format(12.23434),'6.3f'))
SyntaxError: invalid syntax
>>> print(format(12.23434,'6.3f'))
12.234
>>> print(format(12.23434,'6.9f'))
12.234340000
>>> print(format(12.23434,'6.0f'))
12
>>> print(format(12.23434,'9.2f'))
12.23
>>> print(format(12.23434,'3.3f'))
12.234
>>> print(format(0.3456,'.2%'))
34.56%
>>> print(format(0.3456,'3.1%'))
34.6%
>>> print(format(0.3456,'6.1%'))
34.6%
>>> help(raw_input)
Help on built-in function raw_input in module __builtin__:
raw_input(...)
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
>>> str2 = raw_input()
woshihaoren
>>> print str2
woshihaoren
>>> type(str2)
<type 'str'>
>>> age = raw_input(your age:)
SyntaxError: invalid syntax
>>> age = raw_input("your age:")
your age:19
>>> type(age)
<type 'str'>
>>> age = age+1
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
age = age+1
TypeError: cannot concatenate 'str' and 'int' objects
>>> age = int(age)
>>> age = age +1
>>> age
20
>>> f1 = float('12.35')
>>> type(f1)
<type 'float'>
>>> print f1
12.35
>>> weight = float(raw_input("please input your weight:"))
please input your weight:23.14
>>> type(weight)
<type 'float'>
>>> print x,f1
20 12.35
相关文章推荐
- Python中的输入输出方式介绍(Output Format)
- 输入数列,以某数为结束标志, 以"后进先出" 方式生成单链表,输出表中各结点的值;再求表中首结点和尾结点的值。
- MonoRail:页面交互的输入输出方式总结
- Python学习(九) -- 输入/输出
- 使用prompt输入一句英文句子和排序方式(升/降),将所有单词按排序方式排序后在网页上输出
- python 编辑器——python IDLE(python还不错哦,环境和输入输出都这么简单方便)
- 探索 Python,第 8 部分: 用 Python 的输入输出功能读取和写入数据
- 第九周实验报告 任务2 定义Complex类中的<<和>>运算符的重载,实现输入和输出,改造原程序中对运算结果显示方式,使程序读起来更自然。
- python 的密码输入方式
- python_输入输出
- 第九周实验报告任务 1 定义Time类中的<<和>>运算符重载,实现时间的输入输出,改造原程序中对运算结果显示方式,使程序读起来更自然。
- 用 Python 的输入输出功能读取和写入数据
- Python指南--输入和输出
- 用 Python 的输入输出功能读取和写入数据
- python 教程 第十章、 输入/输出
- Win32汇编控制台下的几种输入输出方式
- MonoRail学习笔记七:页面交互的输入输出方式总结
- 7.1.3 输入/输出的控制方式
- Python指南--输入和输出
- 探索 Python,第 8 部分: 用 Python 的输入输出功能读取和写入数据