avatarPranjal Saxena

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2243

Abstract

rameborder="0" height="undefined" width="undefined"> </div> </div> </figure></iframe></div></div></figure><h1 id="adad">3. len()</h1><p id="dbb5">This function is used to find the length of any object. This function is most useful with the range function in Python while iterating over an object.</p> <figure id="ee28"> <div> <div>

            <iframe class="gist-iframe" src="/gist/BetterProgramming/706d825151a9af38d2533345839e9f5b.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><h1 id="1b19">4. isnumeric()</h1><p id="3202">If you want to check if your string has only numeric values, this function can be useful. This function is mostly used with regular expressions validating any object.</p>
    <figure id="ee35">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/BetterProgramming/2cfaeeeff3358b90f13e44ed37bdfa41.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><h1 id="8d1b">5. in</h1><p id="fbab">This is used to check whether an object contains any other object. The object can be a string, list, dictionary, or tuple.</p><div id="4318"><pre>bikes = <span class="hljs-selector-attr">[<span class="hljs-string">'trek'</span>, <span class="hljs-string">'redline'</span>, <span class="hljs-string">'giant'</span>]</span>

ans=<span class="hljs-string">'trek'</span> <span class="hljs-keyword">in</span> bikes <span class="hljs-function"><span class="hljs-title">print</span><span class="hljs-params">(ans)</span></span></pre></div><div id="81f2"><pre>Output <span class="hljs-literal">True</span></pre></div><h1 id="3aef">6. is_upper()</h1><p id="451b">This function is used to check whether all the characters in the strings are in upper case.</p><div id="0377"><pre><span class="hljs-attribute">txt</span> <span class="hljs-operator">=</span> <span class="hljs-string">"THIS IS MeDIUM!"</span> <span class="hljs-attribute">x</span> <span class="hlj

Options

s-operator">=</span> txt.isupper() print(x)</pre></div><div id="aab1"><pre>Output <span class="hljs-literal">False</span></pre></div><h1 id="e1d7">7. join()</h1><p id="209e">This function is mostly used with the split function in Python. While doing the split, we try to split the string into small strings. And on the other hand, the <code>join()</code> function joins all the split items.</p><div id="a850"><pre>myTuple = (<span class="hljs-string">"John"</span>, <span class="hljs-string">"Peter"</span>, <span class="hljs-string">"Vicky"</span>) x = <span class="hljs-string">" "</span><span class="hljs-selector-class">.join</span>(myTuple) <span class="hljs-function"><span class="hljs-title">print</span><span class="hljs-params">(x)</span></span></pre></div><div id="d5b6"><pre><span class="hljs-attribute">Output John Peter Vicky</span></pre></div><h1 id="4ff2">8. isnan()</h1><p id="1940">This function is very handy to check whether an object is NaN or not.</p> <figure id="c662"> <div> <div>

            <iframe class="gist-iframe" src="/gist/BetterProgramming/fcf89c733ca423ddf43a8adeeda0fec7.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><h1 id="e321">9. split()</h1><p id="71f0">This function is mostly used while taking the user input using the <code>input()</code> function. It takes the object as a string and splits the object based on anything.</p><p id="52df">If you want to split a string with the keyword “f,” you can pass this inside the <code>split(“f”)</code> function.</p>
    <figure id="3097">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/BetterProgramming/4d46cbca2c78f2a29c5fe3a84aa0a5b6.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="8b8b">That’s all, folks, for this article. These were the most-used Python shortcuts that we should all be aware of. Do practice them well to utilize them in your day-to-day scripting tasks.</p></article></body>

Advice for Programmers

9 Handy Python Functions for Programmers

Based on my personal scripting experience

Photo by Lindsay Henwood on Unsplash

Python is very handy in terms of shortcuts this language provides. Some of the shortcuts are very useful, make the scripting much faster, and optimizing your code.

These shortcuts are available in the Python libraries, and using them can make your code work faster and more easily. We need to become used to these functions so that we can utilize them when needed and save our time.

In this article, I will share the nine most useful functions I have come up with based on my personal coding experience.

1. reversed()

While programming, we often need to reverse a string or a list. For reversing any object, Python provides a function that can be utilized to optimize your code, instead of using a loop to make it reversed.

2. zip()

The zip() function, for parallel iteration, is very handy when we need to iterate over multiple lists. This function is generally used with a loop and to compare similar indexed elements in each list. Here we can use any number of lists inside the zip() function to iterate over them.

3. len()

This function is used to find the length of any object. This function is most useful with the range function in Python while iterating over an object.

4. isnumeric()

If you want to check if your string has only numeric values, this function can be useful. This function is mostly used with regular expressions validating any object.

5. in

This is used to check whether an object contains any other object. The object can be a string, list, dictionary, or tuple.

bikes = ['trek', 'redline', 'giant']
ans='trek' in bikes
print(ans)
Output
True

6. is_upper()

This function is used to check whether all the characters in the strings are in upper case.

txt = "THIS IS MeDIUM!"
x = txt.isupper()
print(x)
Output
False

7. join()

This function is mostly used with the split function in Python. While doing the split, we try to split the string into small strings. And on the other hand, the join() function joins all the split items.

myTuple = ("John", "Peter", "Vicky")
x = " ".join(myTuple)
print(x)
Output
John Peter Vicky

8. isnan()

This function is very handy to check whether an object is NaN or not.

9. split()

This function is mostly used while taking the user input using the input() function. It takes the object as a string and splits the object based on anything.

If you want to split a string with the keyword “f,” you can pass this inside the split(“f”) function.

That’s all, folks, for this article. These were the most-used Python shortcuts that we should all be aware of. Do practice them well to utilize them in your day-to-day scripting tasks.

Programming
Python
Software Development
Software Engineering
Data Science
Recommended from ReadMedium