Python Syntax/build-in Function All-in-One

1. print Function

The arguments of the print function are the following ones:

print(value1, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

The print function can print an arbitrary number of values ("value1, value2, ..."), which are separated by commas. These values are separated by blanks.

2. The built-in function range(a, b) is the right function to iterate over a sequence of numbers;

it includes a but not b in boundary.

3.  string -> list:

split(str="", num=string.count(str))

Splits string according to delimiter str (space if not provided) and returns list of substrings; split into at most num substrings if given.

splitlines( num=string.count('\n'))

Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed.

4. tuple(seq)

Converts a list into tuple.

5. list(seq)

Converts a sequence into list.

6. set(): sets are lists of strings without duplicated words. set() is used to remove the duplicated elements in a list of string elements;

          ***  if used in formatting list_string.set(), error below will occur:

                  AttributeError: 'list' object has no attribute 'set'

               the correct way should be: set(list_string);

Sample usage code of set()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,779评论 0 33
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,949评论 0 23
  • “量身打造”我很丑,可是我很温柔。一炮而红 因为儿时喜欢音乐,服完兵役后,当上贸易公司的文员。组建了自己的乐队,后...
    肖辉阅读 1,036评论 0 1
  • 今看到这句话,“生命是一个试错的过程,一个人必须透过错误来学习”,我愣了一下,颠覆我的过往认知。从小母亲就告诉我,...
    晨曦尔雅阅读 284评论 0 0
  • 从图书馆出来之后,阿辉说去“转一转”。于是两个人就在校园里乱溜达,走到羽毛球场旁边的转角,风柔柔的吹起我的头发。兴...
    Vick不是Vicky阅读 314评论 0 0