内置函数 print(args, sep=, end=)
最新推荐文章于 2024-10-25 23:02:26 发布

weixin_38892128 于 2019-05-26 10:57:16 发布
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
内置函数官方描述:
def print(self, *args, sep=' ', end='n', file=None): # known special case of 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. """ pass 123456789101112
举例:
print ('a', 'b', 'c', sep='-', end='n') 结果 a-b-c print (*[1,2,3], sep='-', end='n') 结果 1-2-3 12345
案例:
https://www.hackerrank.com/challenges/python-loops/problem
Task
Read an integer . For all non-negative integers , print . See the sample for details.
Input Format
The first and only line contains the integer, .
Constraints
Output Format
Print lines, one corresponding to each .
Sample Input 0
5
Sample Output 0
0
1
4
9
16
答案:
print (*[i**2 for i in range(n)], sep='n' ) 1
相关知识
【面向对象学习笔记day03】面向对象基础语法+内置函数+定义简单的类+创建对象+第一个面向对象程序+使用 Cat 类再创建一个对象+方法中的self参数+初始化方法+内置方法和属性+del+str
Python3 * 和 ** 运算符
Python笔试题
Python之函数
文件学习内容
python学习笔记(四)—— 函数
Python学习笔记(3)——input函数
第8章:函数
Python学习记录——4.input()函数
Python标准库:内置函数property(fget=None, fset=None, fdel=None, doc=None)
原文链接: 内置函数 print(args, sep=, end=) https://www.mcbbbk.com/newsview759435.html
| 上一篇: 1.revit简单获取元素类型 | 下一篇: Flask奇妙探索之旅(五) |





