2-min Computer Science Concepts

What is an Array in Computer Science?

In computer science, an array data structure consists of a collection of elements—usually of the same type such as integer or string. Each element is identified by an array index. Arrays are designed to allow extremely efficient access of individual elements by index: runtime complexity is constant with growing array size! The reason is that …

What is an Array in Computer Science? Read More »

How To Check If a List Is Nested In Python?

Summary: One of the following methods can be used to check if a list is empty :- Method 1: Using isinstance() With any() Method 2: Using isinstance() And len() Methods Within For Loop Problem: Given a list; how to check if it is nested or not? Considering that you have a list such that it is nested at …

How To Check If a List Is Nested In Python? Read More »

How to Use Global Variables In a Python Function?

Summary: Use the global keyword to declare a global variable inside the local scope of a function so that it can be modified or used outside the function as well. To use global variables across modules create a special configuration module and import the module into our main program. The module is available as a …

How to Use Global Variables In a Python Function? Read More »

Python Comments — 2-Minute Guide with Exercise

Wouldn’t reading code be much easier if the author constantly shared their thoughts with you? Commenting is good practice in Python because it helps others (and your future self) understanding your code much better. Writing commented code makes you more productive in the long term! There are two types of comments: one-line comments and multi-line …

Python Comments — 2-Minute Guide with Exercise Read More »

Python raw_input() vs input()

Summary: The key differences between raw_input() and input() functions are the following: raw_input() can be used only in Python 2.x and is obsolete in Python 3.x and above and has been renamed input() In Python 2.x, raw_input() returns a string whereas input() returns result of an evaluation. While in Python 3.x input() returns a string …

Python raw_input() vs input() Read More »

How To Resolve UnboundLocalError On Local Variable When Reassigned After The First Use?

Summary: To resolve an UnboundLocalError when the local variable is reassigned after the first use, you can either use the global keyword or the nonlocal keyword. The global keyword allows you to modify the values of a global variable from within a function’s local scope while the nonlocal keyword provides similar functionality in case of …

How To Resolve UnboundLocalError On Local Variable When Reassigned After The First Use? Read More »