0% found this document useful (0 votes)
6 views

Python BuiltIn Functions Beginners

This document provides an overview of Python built-in functions categorized into Numeric Functions, String Functions, Type Conversion, List and Sequence Functions, Looping Helpers, Dictionary and Set Functions, Functional Tools, and Debugging and Introspection. Each function is accompanied by a brief description and an example of its usage. The content is aimed at beginners looking to understand and utilize Python's built-in capabilities.

Uploaded by

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

Python BuiltIn Functions Beginners

This document provides an overview of Python built-in functions categorized into Numeric Functions, String Functions, Type Conversion, List and Sequence Functions, Looping Helpers, Dictionary and Set Functions, Functional Tools, and Debugging and Introspection. Each function is accompanied by a brief description and an example of its usage. The content is aimed at beginners looking to understand and utilize Python's built-in capabilities.

Uploaded by

amolika406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Built-in Functions for Beginners

Numeric Functions

abs(x): Returns the absolute value of a number. Example: abs(-5) -> 5

round(x, n): Rounds x to n decimal places. Example: round(3.1415, 2) -> 3.14

pow(x, y): Returns x raised to the power y. Example: pow(2, 3) -> 8

divmod(x, y): Returns (x // y, x % y). Example: divmod(9, 4) -> (2, 1)

String Functions

str(x): Converts x to a string. Example: str(123) -> '123'

len(s): Returns the length. Example: len('hello') -> 5

input(prompt): Takes user input. Example: input('Enter name: ')

print(x): Prints output. Example: print('Hello')

Type Conversion

int(x): Converts x to integer. Example: int('5') -> 5

float(x): Converts x to float. Example: float('3.14') -> 3.14

bool(x): Converts x to boolean. Example: bool(0) -> False

complex(x, y): Creates complex number. Example: complex(2, 3) -> (2+3j)

type(x): Returns the type of x. Example: type('hi') -> <class 'str'>


Python Built-in Functions for Beginners

isinstance(x, type): Checks type. Example: isinstance(5, int) -> True

List and Sequence Functions

list(): Creates a new list. Example: list('abc') -> ['a', 'b', 'c']

sum(list): Returns sum. Example: sum([1, 2, 3]) -> 6

min(list) / max(list): Returns smallest/largest. Example: min([3,1]) -> 1

sorted(list): Returns sorted list. Example: sorted([3,1,2]) -> [1,2,3]

reversed(list): Returns reversed iterator. Example: list(reversed([1,2,3])) -> [3,2,1]

Looping Helpers

range(start, stop, step): Generates a sequence. Example: range(1,5) -> 1,2,3,4

enumerate(iterable): Returns index and item. Example: enumerate(['a','b'])

zip(list1, list2): Combines lists. Example: zip([1,2],[3,4]) -> (1,3),(2,4)

Dictionary and Set Functions

dict(): Creates dictionary. Example: dict(a=1, b=2) -> {'a': 1, 'b': 2}

set(): Creates set. Example: set([1,2,2,3]) -> {1,2,3}

Functional Tools

map(func, iterable): Applies function. Example: map(str, [1,2]) -> ['1','2']

filter(func, iterable): Filters items. Example: filter(lambda x: x>0, [-1,2]) -> [2]
Python Built-in Functions for Beginners

any(iterable): True if any item is true. Example: any([False, True]) -> True

all(iterable): True if all items are true. Example: all([True, True]) -> True

Debugging and Introspection

help(object): Shows help. Example: help(str)

dir(object): Lists attributes. Example: dir([])

id(object): Returns memory address. Example: id(42)

You might also like