Python string method split() inputs a string value & outputs a list of words contained within the string by separating or splitting the words on all the whitespaces by default. It also has an optional argument for limiting the number of splits.

The split() method converts the string into other data types like lists by breaking a string into pieces. Python provides us with two methods: .split() and .rsplit().

Both .split(), & .rsplit() take a separating element by which we are splitting the string, & a maxsplit tells us the maximum number of substrings we want.

Example of Using the .split() Method


if…elif…else are conditional statements that provide us with the decision making that is required when we want to execute code based on a particular condition.

The if…elif…else statement used in Python helps automate that decision making process.

if Condition

The if condition is considered the simplest of the three & makes a decision based on whether the condition is true or not. If the condition is true, it prints out the indented expression. If the condition is false, it skips printing the indented expression.


In Python, we can use a list function which creates a collection that can be manipulated for our analysis. This collection of data is called a list object.

While all methods are functions in Python, not all functions are methods. There is a key difference between functions & methods in Python. Functions take objects as inputs. Methods in contrast act on objects.

Python offers the following list functions:

  • sort(): Sorts the list in ascending order.
  • type(list): It returns the class type of an object.
  • append(): Adds a single element to a list.
  • extend(): Adds multiple elements to a list.
  • index()


Numpy’s random module, a suite of functions based on pseudorandom number generation. Random means something that can not be predicted logically.

np.random.seed() Function

In this example, we will stimulate a coin flip. We will use the function np.random(), which draws a number between 0 & 1 such that all numbers in this interval are equally likely to occur.

If the number we draw is less than 0.5, which has a 50% chance of happening, we say heads & tails otherwise. This type of result where results are either True (Heads) or False (Tails) is referred to as Bernoulli trial.

The pseudorandom number…


Python’s rename column is a method used to change the column nambes with Pandas’ rename function. It’s useful when we load a tabular dataset that has no column names or if we want to assign different names to specific columns.

Syntax

Its syntax is given as:


When working with data, we are often going to need to count items, create dictionaries values before we know keys to store them in, or maintain order in a dictionary.

Counter is a powerful tool for counting, validating, & learning more about the elements within a dataset that is found in the collections module. We pass an iterable (list, set, tuple) or a dictionary to the Counter. We can also use the Counter object similarly to a dictionary with key/value assignment, for example, counter[key] = value.

A common usage for Counter is checking data for consistency prior to using it.

Counter Module


Just like in mathematics, programming languages like Python have operators. We can think of them as extremely simple functions that lie at the basis of computer science. These are the simplest operations to which a computer program can be reduced. They are essential knowledge for any aspiring Data Scientist or Software Engineer.

In this tutorial, we’ll learn about:

  • The different types of operators: Arithmetic, Assignment, Comparison & Logical
  • Operator Overloading
  • Precedence
  • Associativity

Arithmetic Operators

These will probably me the most familiar with us, since they come from basic mathematics.

The arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), exponent…


Introduction

What Is String Formatting?

String formatting is attractively designing our string using formatting techniques provided by the particular programming language. We have different string formatting techniques in Python. We are now going to explore the new f-string formatting technique.

f-string evaluates at runtime of the program. It’s swift compared to the previous methods.

f-string having an easy syntax compared to previous string formatting techniques of Python. We will look into every bit of this formatting using different examples.

Syntax

Every f-string statement consists of two parts, one is character f or F, & the next one is a string which…


A lot of us, while reading this tutorial, might think that there is nothing undiscovered about a simple Python Print function since we all would have started learning Python with the evergreen example of printing Hello, World!. It's also true that Python or, for that matter, any programming language, the Print function is the most basic & the baby step that we take while learning a particular language. …


A global interpreter lock (GIL) is a mechanism to apply a global lock on an interpreter. It is used in computer-language interpreters to synchronize & manage the execution of threads so that only one native thread (scheduled by the operating system) can execute at a time.

In a scenario where we have multiple threads, what can happen is that both the thread might try to acquire the memory at the same time, & as a result of which they would overwrite the data in the memory. Hence, arises a need to have a mechanism that could help prevent this phenomenon.

Jason Joseph

Data Scientist & Machine Learning Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store