0% found this document useful (0 votes)
2 views8 pages

Python Function Docs Explained

The document provides a detailed overview of common Python functions, including their syntax, explanations, and examples. Key functions covered include print, len, range, input, int, float, str, type, sum, max, min, sorted, abs, round, enumerate, zip, map, filter, open, and help. Each function is described with its parameters and a sample usage to illustrate its application.

Uploaded by

aicanbegreater
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Python Function Docs Explained

The document provides a detailed overview of common Python functions, including their syntax, explanations, and examples. Key functions covered include print, len, range, input, int, float, str, type, sum, max, min, sorted, abs, round, enumerate, zip, map, filter, open, and help. Each function is described with its parameters and a sample usage to illustrate its application.

Uploaded by

aicanbegreater
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Common Python Functions – Documentation Syntax Explained

print
Syntax:

print(*objects, sep=' ', end='\n', file=[Link], flush=False)

Explanation:

*objects – any number of values to print

sep – separator placed between objects

end – what is printed at the end (default newline)

file – output stream (usually the terminal)

flush – forces the buffer to immediately send output to the terminal

Example:

print("Hello", "World", sep="-")

len
Syntax:

len(obj)

Explanation:

obj – any container (string, list, tuple, set, dictionary)

Returns the number of elements.

Example:

len("hello") # 5

range
Syntax:
range(stop)

range(start, stop[, step])

Explanation:

start – starting number

stop – ending limit (not included)

step – increment value

Square brackets [] mean optional parameters.

Example:

range(1, 10, 2)

input
Syntax:

input(prompt=None)

Explanation:

prompt – message shown before input

None – means no default prompt

Example:

name = input("Enter your name: ")

int
Syntax:

int(x=0, base=10)

Explanation:

x – value to convert into an integer


base – number system base

Example:

int("101", 2)

float
Syntax:

float(x=0.0)

Explanation:

x – value converted into a floating-point number

Example:

float("3.14")

str
Syntax:

str(object='')

Explanation:

object – value converted into a string

Example:

str(42)

type
Syntax:

type(object)

type(name, bases, dict)


Explanation:

object – value whose type you want to inspect

Second form is used to dynamically create classes.

Example:

type(5)

sum
Syntax:

sum(iterable, start=0)

Explanation:

iterable – collection of numbers

start – initial value added before summing

Example:

sum([1,2,3])

max
Syntax:

max(iterable, *[, key, default])

max(arg1, arg2, *args[, key])

Explanation:

iterable – collection to evaluate

key – function used for comparison

default – value returned if iterable is empty

Example:

max([3,7,2])
min
Syntax:

min(iterable, *[, key, default])

min(arg1, arg2, *args[, key])

Explanation:

Works like max() but returns the smallest value.

Example:

min([3,7,2])

sorted
Syntax:

sorted(iterable, *, key=None, reverse=False)

Explanation:

iterable – items to sort

key – function determining comparison value

reverse – True sorts in descending order

Example:

sorted([5,1,4])

abs
Syntax:

abs(x)

Explanation:
x – number

Returns the absolute (non-negative) value.

Example:

abs(-5)

round
Syntax:

round(number, ndigits=None)

Explanation:

number – value to round

ndigits – number of decimal places

Example:

round(3.14159,2)

enumerate
Syntax:

enumerate(iterable, start=0)

Explanation:

iterable – collection to loop through

start – starting index

Example:

for i, v in enumerate(["a","b"]):

pass
zip
Syntax:

zip(*iterables, strict=False)

Explanation:

*iterables – multiple collections combined element-wise

strict – ensures equal lengths

Example:

zip([1,2],[3,4])

map
Syntax:

map(function, *iterables)

Explanation:

function – function applied to each element

iterables – collections providing elements

Example:

map(int, ["1","2"])

filter
Syntax:

filter(function, iterable)

Explanation:

function – condition function returning True/False

iterable – collection to filter


Example:

filter(lambda x: x>5, [2,7,9])

open
Syntax:

open(file, mode='r', buffering=-1, encoding=None)

Explanation:

file – file path

mode – read/write mode

buffering – buffer control

encoding – text encoding

Example:

open("[Link]","r")

help
Syntax:

help(object=None)

Explanation:

object – function, module, or class to inspect

Displays documentation in the interpreter.

Example:

help(print)

You might also like