您的位置:首页 > 编程语言 > Python开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐