Python Tutorial

Introduction Python Features Python Applications System requirements for Python Python Installation Python Basics Python Variables Python Data Types Python IDE Python Keywords Python Operators Python Comments Python Pass Statement

Python Conditional Statements

Python if Statement Python elif Statement Python If-else statement Python Switch Case

Python Loops

Python for loop Python while loop Python Break Statement Python Continue Statement Python Goto Statement

Python Arrays

Python Array Python Matrix

Python Strings

Python Strings Python Regex

Python Built-in Data Structure

Python Lists Python Tuples Python Lists vs Tuples Python Dictionary Python Sets

Python Functions

Python Function Python min() function Python max() function Python User-define Functions Python Built-in Functions Anonymous/Lambda Function in Python

Python File Handling

Python File Handling Python Read CSV Python Write CSV Python Read Excel Python Write Excel Python Read Text File Python Write Text File Read JSON File in Python

Python Exception Handling

Python Exception Handling Python Errors and exceptions Python Assert

Python OOPs Concept

OOPs Concepts in Python Classes & Objects in Python Inheritance in Python Polymorphism in Python Python Encapsulation Python Constructor Static Variables in Python Abstraction in Python

Python Iterators

Iterators in Python Yield Statement In Python

Python Generators

Python Generator

Python Decorators

Python Decorator

Python Functions and Methods

Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods

Python Modules

Python Modules Python Datetime Module Python Calendar Module  

Python MySQL

Python MySQL Python MySQL Update Operation Python MySQL Delete Operation

Python MongoDB

Python MongoDB

Python Data Structure Implementation

Python Stack Python Queue Python Hash Table Python Graph

Python Advance Topics

Speech Recognition in Python Face Recognition in Python Python Rest API Python Command Line Arguments Python JSON Python Virtual Environment Type Casting in Python Collections in python Python Enumerate Python Debugger Python DefaultDict


Python PPTX Python Pickle Python Seaborn Python Coroutine Python EOL Python Infinity Python math.cos and math.acos function Python Project Ideas Based On Django Reverse a String in Python Reverse a Number in Python Python Word Tokenizer Python Trigonometric Functions Python try catch exception GUI Calculator in Python Implementing geometric shapes into the game in python Installing Packages in Python Python Try Except Python Sending Email Socket Programming in Python Python CGI Programming Python Data Structures Python abstract class Python Compiler Python K-Means Clustering List Comprehension in Python3 NSE Tools In Python Operator Module In Python Palindrome In Python Permutations in Python Pillow Python introduction and setup Python Functionalities of Pillow Module Python Argmin Python whois Python JSON Schema Python lock Return Statement In Python Reverse a sentence In Python tell() function in Python Why learn Python? Write Dictionary to CSV in Python Write a String in Python Binary Search Visualization using Pygame in Python Latest Project Ideas using Python 2022 Closest Pair of Points in Python ComboBox in Python Python vs R Python Ternary Operators Self in Python Python vs Java Python Modulo Python Packages Python Syntax Python Uses Python Logical Operators Python Multiprocessing Python History Difference between Input() and raw_input() functions in Python Conditional Statements in python Confusion Matrix Visualization Python Python Algorithms Python Modules List Difference between Python 2 and Python 3 Is Python Case Sensitive Method Overloading in Python Python Arithmetic Operators Design patterns in python Assignment Operators in Python Is Python Object Oriented Programming language Division in Python Python exit commands Continue And Pass Statements In Python Colors In Python Convert String Into Int In Python Convert String To Binary In Python Convert Uppercase To Lowercase In Python Convert XML To JSON In Python Converting Set To List In Python Covariance In Python CSV Module In Python Decision Tree In Python Difference Between Yield And Return In Python Dynamic Typing In Python Abstract design pattern in python Builder design pattern in python Prototype design pattern in Python Creational design patterns in Python

How to

How to convert integer to float in Python How to reverse a string in Python How to take input in Python How to install Python in Windows How to install Python in Ubuntu How to install PIP in Python How to call a function in Python How to download Python How to comment multiple lines in Python How to create a file in Python How to create a list in Python How to declare array in Python How to clear screen in Python How to convert string to list in Python How to take multiple inputs in Python How to write a program in Python How to compare two strings in Python How to create a dictionary in Python How to create an array in Python How to update Python How to compare two lists in Python How to concatenate two strings in Python How to print pattern in Python How to check data type in python How to slice a list in python How to implement classifiers in Python How To Print Colored Text in Python How to develop a game in python How to print in same line in python How to create a class in python How to find square root in python How to import numy in python How to import pandas in python How to uninstall python How to upgrade PIP in python How to append a string in python How to open a file in python


Python Sort List Sort Dictionary in Python Python sort() function Python Bubble Sort


Factorial Program in Python Prime Number Program in Python Fibonacci Series Program in Python Leap Year Program in Python Palindrome Program in Python Check Palindrome In Python Calculator Program in Python Armstrong Number Program in Python Python Program to add two numbers Anagram Program in Python Even Odd Program in Python GCD Program in Python Python Exit Program Python Program to check Leap Year Operator Overloading in Python Pointers in Python Python Not Equal Operator Raise Exception in Python Salary of Python Developers in India What is a Script in Python Singleton design pattern in python

Python Built-in Functions

Python Built-in Functions

The Python interpreter has a number of functions and types built into it that are always available. The Python built- in functions are as follow:

Methods Explaining
abs() The abs() function returns the absolute value of a number
all() The all() function returns True if all items in an iterable object are true.
any() The any() function returns True if any item in an iterable object is true
ascii() This function returns a readable version of an object.
bin() The bin() function convert an integer number to a binary string prefixed with “0b”.
bool() The bool()class returns the boolean value for the given object
bytearray() The bytearray()class returns an array of bytes
bytes() The byte()class returns a bytes object.
chr() The chr() function returns a character from the specified Unicode code.
compile() This function returns the specified source as an object, ready to be executed
complex() This function returns a complex number
delattr() The delattr() function deletes the specified attribute (property or method) from the specified object
dict() The dict() function returns a dictionary (Array)
dir() This function returns the list of names in the current local scope
divmod() The divmod() function returns the quotient and the remainder when argument1 is divided by argument2.
enumerate() The enumerate() function returns an enumerate object.
eval() The eval() function evaluates and executes an expression.
filter() The filter() function constructs an iterator from those elements of iterable for which function returns true.
float() This class returns a floating point number constructed from a number or string x.
format() This function Formats the specified value.
frozenset() The frozenset() function returns a frozenset object
getattr() This function returns the value of the named attribute of object.
globals() The globals() function returns a dictionary representing the current global symbol table.
hasattr() The hasattr() function returns True if the specified object has the specified attribute (property/method)
hash() The hash() function returns the hash value of the object. 
hex() This function converts an integer number to a lowercase hexadecimal string prefixed with “0x”.
id() The id() function returns the “identity” of an object.
input() The input() function reads a line from input, converts it to a string and returns that string.
int() The int() function returns an integer object constructed from a number or string x, or return 0 if no arguments are given.
isinstance() This function returns a boolean value true if the object argument is an instance of the classinfo argument, or of a subclass thereof.
issubclass() The issubclass() returns a boolean value true if class is a subclass (direct, indirect or virtual) of classinfo.
iter() This function returns an iterator object.
len() The len() function returns the length (the number of items) of an object.
list() This list() function returns a list.
locals() The locals() updates and returns a dictionary representing the current local symbol table.
map() This function returns the given iterator with the specified function applied to each item.
max() The max()returns the largest item in an iterable or the largest of two or more arguments.
memoryview() This function returns a “memory view” object created from the given argument.
min() The min() function returns the smallest item in an iterable or the smallest of two or more arguments.
next() The next()function returns the next item in an iterable
object() The object()function returns a new object
oct() The oct() function converts a number into an octal
open() This function opens a file and returns a file object
ord() This function converts an integer representing the Unicode of the specified character
pow() The pow()function returns x to the power y; if z is present, return x to the power y, modulo z
print() This function prints objects to the text stream file.
property() The property() function returns a property attribute.
range() The range()function returns a sequence of numbers, starting from 0 and increments by 1 (by default)
repr() This function returns a string containing a printable representation of an object.
reversed() The reversed() function returns a reverse iterator. 
round() The round() function returns the number by rounding to ndigits precision after the decimal point.
set() The set() function returns a new set object, optionally with elements taken from iterable.
setattr() This function sets an attribute (property/method) of an object.
slice() The slice() function returns a slice object.
sorted() This function returns a new sorted list from the items in iterable.
str() The str() function returns a str version of object.
sum() This function sums the items of the specified iterator
tuple() The tuple() function returns a tuple
type() The type() function returns the type of an object.
vars() This function returns the __dict__ property of an object.
zip() This function returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.

Example 1

 # Python Program explaining 
 # built-in function 
 # abs() built-in function   
 # passing floating point number 
 float_val = -54.26
 print('Absolute value for integer number:', abs(float_val)) 
 # passing An integer number
 int_val = -94
 print('Absolute value for float number:', abs(int_val)) 
 # passing a complex number 
 complex_val = (3 - 4j) 
 print('Absolute value for complex number:', abs(complex_val))
 #all() function
 # will return True and the same will be printed 
 print ('The all() function will return: ',all([True, True, True])) 
 # any() function
 #  item (True) and will return True. 
 print ('The any() function will return: ',any([False, True, False, False, False, True])) 
 # ascii() function
 inp_str = "H ë ê L O ? W O R L D"
 print ("The ascii() function:",ascii(inp_str))
 # bin() built-in function 
 x = bin(136)
 print('The bin() function returns: ',x) 


 Absolute value for integer number: 54.26
 Absolute value for float number: 94
 Absolute value for complex number: 5.0
 The all() function will return:  True
 The any() function will return:  True
 The ascii() function: 'H \xeb \xea L O ? W O R L D'
 The bin() function returns:  0b10001000 

Example 2

 # Python Program explaining  
 # built-in function 
 # bool class
 # Returns False as val1 is not equal to val2 
 val1 = 5
 val2 = 10
 print("Both the values are equal:",bool(val1==val2)) 
 # bytearray() class  
 inp_str = "HelloWorld"
 # encoding the string with unicode 8 and 16 
 inp_array1 = bytearray(inp_str, 'utf-8') 
 print("The bytearray() function returns:",inp_array1)
 # chr() function 
 # returning the char value
 print(chr(72), chr(101), 
 chr(101), chr(108), 
 chr(111), chr(32), 
 chr(87), chr(111), 
 # complex() class
 val1 = complex(11) # Passing single parameter  
 # passing the output
 print(“The complex value:”,val1)   


 Both the values are equal: False
 The bytearray() function returns: bytearray(b'HelloWorld')
 H e e l o   W o r l d
 The complex value:  (11+0j) 

Example 3

 # Python Program explaining  
 # built-in function 
 # the filter() function
 # a list contains both even and odd numbers.  
 values = [10, 11, 12, 13, 15, 18, 103] 
 print("List: ",values)
 # filter() returning odd numbers of the list 
 even_val = filter(lambda x: x % 2!=0, values) 
 print("Even Values: ",list(even_val)) 
 #Applying float() funcion
 x = float(6)
 print("After float() function: ",x)
 # the format() function
 val= 0.09
 print("Number: ",val)
 #formating the specified value
 x = format(val, '%')
 print("After format() function: ",x)
 #frozenset() function
 # tuple of numbers 
 val = (11, 12, 13, 14, 15, 16, 17, 18, 19) 
 # converting tuple to frozenset 
 f_num = frozenset(val) 
 # printing details 
 print("frozenset returns: ", f_num) 


 List:  [10, 11, 12, 13, 15, 18, 103]
 Even Values:  [11, 13, 15, 103]
 After float() function:  6.0
 Number:  0.09
 After format() function:  9.000000%
 frozenset returns:  frozenset({11, 12, 13, 14, 15, 16, 17, 18, 19})