>>> 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的输入输出就总结到这里了!