Built in functions in Python

Built-in functions in Python are a set of predefined functions that are available to use in any Python program without the need to import any additional modules or libraries.

These functions provide a wide range of functionality, including mathematical operations, string manipulation, data structure manipulation, and input/output operations.

List of Built-in functions in Python

absAbsolute value of input number
allto check all elements of iterable for True of False
anyto check any elements of iterable for True of False
asciiPrintable chars in the object
binConverting integer to Binary
boolReturn True or False based on input object
breakpointStop execution for debugging
bytearraymutable array of bytearray
bytesReturn bytes object
callableChecking if object is Callable or not
chrUnicode pint value to get Char
classmethoda class method for the function
compilecode object from AST or source String
complex Complex number with real & imaginary parts
copyright Display coyright constant value
creditsDisplay credit constant value
delattrDeleting attribute of an object
dict Dictionary object
dir list of attributes and methods
displaydisplay objects in frontend
divmodquotient and remainder of two input numbers
enumerateAdding incremental counter to iterable object
evalDynamic evalution of python code
execDynamic execution of code
filterFilter out elements of an iterable
floatConverting string to float dtype
formatFormatting outputs
frozensetMaking elements of iterable object to immutable
get_ipython
getattr Getting value of the attribute
globals Dictionary of global symbol table
hasattrChecking the attribute
hashhash value of object
helpbuilt-in help document system
hexHex string from input number
idIdentity of the object
inputInput box for user data entry
intString or number to Integer
isinstanceChecking if object is instance of a class
issubclassChecking if class is subclass or input class or not
iterCreating iterator object
lenNumber of elements present in an iterable or string
license Display license constant value
listmutable object with elements
localsdictionary of symbol table
mapapply function to each element of iterables
maxMaximum value of the iterable or string or series
memoryview
minMinimum value of the iterable or string or series
nextNext element of an iterator
objectObject as function
oct Octal string from input number
open Read a file
ord Unicode point value of the input char
pow x to the power of y
printReturning the object to screen or file
property
range Sequence of numbers
reprUnambiguous string representation of an object
reversedReturns a reversed iterator
roundRounded value of a number
setUnordered and unindexed list
setattr Add / update value of attribute
slicebreaking list, tuple, string etc by using slice object
sortedNew sorted list from an iterable
staticmethodstatic method for a given function
strConverting object to string
sumsum of elements of an iterater
superto access methods of base class
tupleimmutable object with elements
type Data type of the object
varsthe __dict__ attribute of the object
zip iterator object by using different iterables
import builtins
for i in dir(builtins):
    print(i)
print("Total Builtin Functions : ",len(dir(builtins)))
Based on the version of Python we are using the number of Builtin functions will varry.
Total Builtin Functions :  158

Checking if a word is Built-in function or not

import builtins
if 'sum' in dir(builtins):
    print(' sum is a built-in function' )
else:
    print(' No it is not a built-in function')
Output
 sum is a built-in function

Can I use builtin functions as variable names ?

No, it's generally not recommended to use built-in functions as variable names in Python. While it's technically possible in some cases, doing so can lead to several drawbacks and potential issues:

Naming Conflicts and Overriding:

Python reserves certain names for built-in functions, classes, and modules. Assigning those names to your variables would make them inaccessible, as your variable would take precedence within its scope.

Even if a built-in function isn't directly used in the same scope, there's a risk of accidentally overriding its intended behavior later in your code, leading to unexpected results.

Examples

#int=225 # this line will override the built-in function int()
x=int(input('Enter a number : '))
print(x*2)
Reserved words as variables are not allowed (error ) but Built-in function we can use.
#True=50 # reserved words as variables are not allowed
x=sum([5,7]) # sum is a built-in function
sum=50 # Use of Built-in functions as variables allowed
#x=sum([6,7])
print(sum)

How to avoid using built-in functions or reserved words ?

Use descriptive names:
  • Choose names that reflect the variable's content or purpose.
  • Explain what the variable holds, making your code self-documenting.
  • Avoid ambiguous names like x, temp, or data.
  • Instead, use names like first_name, total_price, or average_score.
To minimize the risk of accidentally overriding built-in functions, consider using a consistent prefix for your variable names. This is a common practice that promotes code readability and maintainability.

Example:
Popular prefixes include my_, user_, or custom_. This improves code clarity and helps distinguish your variables from built-in functions.




  • Python built-in functions , listing all and checking #python #pythonbasic
    15-Feb-2024 quixote


Reserved Keywords in Python User Defined Functions variables in Python


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer