Nov 19, 2016

raw_iput と print

今回のPostは、raw_input()とprintを紹介したいです。二つ函数とも build-in function でございます。

>>> 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.



上記の英語から、raw_input()の意味はなんとなくわかると思います。試しましょう!


>>> raw_input("input your name:")
input your name:HelloPython
'HelloPython'
>>> 
>>> name=raw_input("input your name:")
input your name:HelloPython
>>> name
'HelloPython'
>>> type(name)

>>> age = raw_input("How old are you?")
How old are you?30
>>> age
'30'
>>> type(age)


>>> print "Hello world"
Hello world
>>> a = "Hello"
>>> b = "python"
>>> print a
Hello
>>> print b
python
>>> 
>>> print a, b
Hello python

No comments:

Post a Comment