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);

Python Syntax/build-in Function All-in-One_第1张图片
Sample usage code of set()

你可能感兴趣的:(Python Syntax/build-in Function All-in-One)