>>> help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.從描述中能夠看出的是print是支持不定參數的,默認輸出到標準輸出,並且不清空緩存。
>>> print("hello","Pyhton",sep="--",end="...");print("!") hello--Pyhton...!經過help命令咱們能夠很清楚的明白print函數的參數列表,這對於咱們對print的認識是有
咱們知道C語言中能夠實現格式化的輸出,其實Python也能夠,接下來筆者也將一一的python
去嘗試。程序員
一、輸出整數。>>> print("the length of (%s) is %d" %('Python',len('python')),end="!") the length of (Python) is 6!二、其餘進制數。
>>> number=15 >>> print("dec-十進制=%d\noct-八進制=%o\nhex-十六進制=%x" % (number,number,number)) dec-十進制=15 oct-八進制=17 hex-十六進制=f三、輸出字符串
>>> print ("%.4s " % ("hello world")) hell
>>> print("%5.4s" %("Hello world")) Hell這裏輸出結果爲「 Hello」,前面有一個空格
>>> print("%*.*s" %(5,4,"Hello world")) Hell這裏對Python的print字符串格式輸出形式
>>> print("%10.3f" % 3.141516) 3.142浮點數的輸出控制和字符串類似,不過序注意的是.3表示的輸出3位小數, 最後一面按四
input(...) 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. >>>注意這裏筆者的Python是3.3的,根據上面的描述能夠很清楚的看到,input函數是從標準輸入流
>>> name = input("your name is:") your name is:kiritor >>> print(name) kiritor >>>查看官方文檔咱們能夠更清楚的明白input是如何工做的。
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:ok,對於Python的輸入輸出就總結到這裏了!