top of page

Miscellaneous Functions ft. Python

Image depicting miscellaneous functions in python.

You use Python every day, yet you might be ignoring some of the most useful and game changing functions. Not because they’re difficult but because people don’t talk much about these functions.


Most of the time we think Python only has print(), len() or type().


But as you grow, you slowly understand that in python there are dozens of small yet powerful helper functions that:

  • save time

  • reduce code length

  • improve readability

  • prevent bugs


So, What are these small yet helpful functions called?

These are called MISCELLANEOUS functions – Not because there are unimportant but because they don’t belong to a single category like math or strings.


In this blog we will deeply explore, on how these functions work along with real examples and code outputs.

What are MISCELLANEOUS FUNCTIONS?

Miscellaneous functions are python built in functions that:

  • work on different datatypes 

  • help in printing, checking, converting, looping and comparing values.

Now let us look into some of the most used miscellaneous functions:


  1. id():


    This function is used to know memory location.


Example:


a = 10
b = 10
print(id(a))
print(id(b))

Output:


140732920346112
140732920346112
In this example, a and b reference the same object in memory because Python optimises integer storage through integer interning.
  1. enumerate():


    This function is used to display the index + value together.


Example:


languages = ["Python", "Java", "C++"]
for index, value in enumerate(languages:
    print(index, value)

Output:


0 Python
1 Java
2 C++
enumerate() function is cleaner and easier than using counters.
  1. zip():


    This function is used to loop multiple lists together. It takes values from multiple lists together, one by one.


Example:


names = ["A", "B", "C"]
marks = [90, 85, 88]
for n, m in zip(names, marks):
    print(n, m)

Output:


A 90
B 85
C 88
zip() function is very much useful in data handling.
  1. all():


    This function returns true if all values are true.


Example:


print(all([True, True, False]))

Output:


False
  1. any():


    This function returns true if atleast one value is true.


Example:


print(any([False, False, True]))

Output:


True
any() and all() functions are used in validations and conditions.

Comments


bottom of page