Mark As Completed Discussion

Over the past few years, Python has gained popularity for its user-friendly nature and efficiency. If you've experienced other programming languages, you'll immediately appreciate its simple syntax and helpful characteristics.

The Python language is a legible and understandable one. This is what we mean by "user friendly" -- it reads almost like the English language. Even those who haven't programmed can comprehend what each line of code might do, and can take a guess of what is expected to happen upon execution.

Introduction

Python isn't just limited to Windows (the operating system). It also works on operating systems like Linux, Solaris, macOS, etc. It's also an open-source language, so those who wish can fork it, add to it, or modify it to their heart's desire.

In terms of its applications, there are several. Because of its advanced features, it sees usage in fields like machine learning, AI, game development, website development, and many more. Additionally, it supports object-oriented programming (OOP), among other programming paradigms.

This tutorial aims to review the main concepts of Python that you need to ace your interview. So, without further ado-- let's get started with the interview questions.

Let's test your knowledge. Click the correct answer from the options.

In Python, what data structure are namespaces implemented as?

Click the option that best answers the question.

  • Object
  • List
  • Dictionary
  • Tuple

What are namespaces in Python?

Before answering what namespaces are, let's quickly review some prior concepts. As you may remember, everything in Python is an object. Each object should have a unique name. For example, if you created a string for the word 'school':

PYTHON
1place = "school"

The string "school" is an object whose name is place. This object is stored with a specific address that points to its location in memory.

The answer to the question "what are Python namespaces?" will be more intuitive with this background. You can think of them as containers that inhabit these objects along with their names. Interesting! Let's dive deeper.

Namespaces

When we execute our program, namespaces are created. The name of each object acts as a key and the object itself as a value. Every function, module, or library has its own unique namespaces. If we import the NumPy library, then upon execution of our program, the Python interpreter will generate NumPy's namespace.

Build your intuition. Is this statement true or false?

Every object in Python has a data type.

Press true if you believe the statement is correct, or false otherwise.

List the basic supported data types

Computer Science is all about data-- exporting it, processing it, loading it, etc. Each piece of data has a type. For example, if we have a number, then its type is numeric. This identification is useful while programming to mentally categorize different objects.

Python supports multiple data types, and each has its own syntax and significance. The following are the main forms of data, and each is broken down into other types.

  • Numeric data
  • Text data
  • Boolean data

Let's dive into each one.

Note: In dynamically-typed languages like Python, we don't declare types explicitly. We create a variable and can immediately assign data to it. The interpreter then determines the intrinsic type. If you ever wanted to know the data type of an object, you can use type() function.

Numeric Data

In Python, numeric information is represented by the following three data types:

  1. int - the data type int is for integers or the numbers that don't have the decimal point.

  2. float- the data type float is for numbers with decimal points.

  3. complex - the data type complex is for the numbers that contain an imaginary value. Let's implement one of each:

PYTHON
1intVariable = 5
2floatVariable = 4.5
3complexVariable = complex(4, 3)

Now, if we want to check the types using the type() function:

PYTHON
1print(type(intVariable))
2print(type(floatVariable))
3print(type(complexVariable))

The output will be:

PYTHON
1<class 'int'>
2<class 'float'>
3<class 'complex'>
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Text Data

The type string represents text data. Most text data contains alphabetical and alphanumeric information. Anything enclosed in ' ' or " " is a string. It can be any number, word, sentence, or special character. Let's see it in action:

PYTHON
1string1 = "Minahil"
2string2 = 'Minahil123'
3string3 = 'Min@hi!'

Now, if we check the data types using type() function:

PYTHON
1print(type(string1))
2print(type(string2))
3print(type(string3))

The output will be:

PYTHON
1<class 'str'>
2<class 'str'>
3<class 'str'>
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Boolean Data

In Python, boolean data has either a True or False value. For example,

PYTHON
1data = True
2data1 = False

Now, if we check the data types using type() function:

PYTHON
1print(type(data))
2print(type(data1))

The output will be:

PYTHON
1<class 'bool'>
2<class 'bool'>
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Are you sure you're getting this? Fill in the missing part by typing it in.

To execute a function, we need to __ that function.

Write the missing line below.

What are the most commonly used built-in functions in Python?

The commonly used built-in functions in Python are:

  • print()
  • len()
  • min()
  • max()
  • type()
  • isinstance()

The details of these functions are given below:

FunctionDescription
print()It is used to display anything on the console.
len()It is used to find the length of a string, list, tuple, dictionary, etc.
min()It is used to find the minimum value out of multiple values.
max()It is used to find the maximum value out of multiple values.
type()It tells about the data type of a variable.
isinstance()It confirms if a variable is of xyz type. For example, if 5 is int? This function returns True if yes.

Let's try out each function for a better understanding.

len()

We can find the length of a string, list, tuple, and a dictionary using the len() function. Let's create one of each and find their lengths.

PYTHON
1string = "Minahil"
2Flowers_List = ["Tulip", "Jasmine", "Rose", "Lili", "Daisy"]
3Number_Tuple = ("one", "two", "three")
4General_Dictionary = {
5    "key1": "value1",
6    "key2": "value2",
7    "key3": "value3",
8    "key4": "value4",
9}

Now, we will find the length using len() function.

PYTHON
1print("The length of string is", len(string))
2print("The length of list is", len(Flowers_List))
3print("The length of tuple is", len(Number_Tuple))
4print("The length of dictionary is", len(General_Dictionary))

The output will be:

PYTHON
1The length of string is 7
2The length of list is 5
3The length of tuple is 3
4The length of dictionary is 4
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

min()

The min() function finds the minimum value of a string, list, tuple, dictionary or multiple values passed as a parameter. Let's find the minimum values of the string, list, tuple and dictionary created prior.

PYTHON
1print("The minimum value of string is", min(string))
2print("The minimum value of list is", min(Flowers_List))
3print("The minimum value of tuple is", min(Number_Tuple))
4print("The minimum value of dictionary is", min(General_Dictionary))

The output will be:

PYTHON
1The minimum value of string is M
2The minimum value of list is Daisy
3The minimum value of tuple is one
4The minimum value of dictionary is key1

Now if we pass multiple values in min() function as parameter, let's see what happens

PYTHON
1min(1, 4, -5, 6, -10, 0)

The output will be:

PYTHON
1-10
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

max()

The max() function finds the maximum value of a string, list, tuple, dictionary, or of multiple values passed to it as parameters. Let's find the maximum values using the string, list, tuple and dictionary created before.

PYTHON
1print("The maximum value of string is", max(string))
2print("The maximum value of list is", max(Flowers_List))
3print("The maximum value of tuple is", max(Number_Tuple))
4print("The maximum value of dictionary is", max(General_Dictionary))

The output will be:

PYTHON
1The maximum value of string is n
2The maximum value of list is Tulip
3The maximum value of tuple is two
4The maximum value of dictionary is key4

Now if we pass multiple values in max() function as parameter, let's see what happens

PYTHON
1max(1,4,-5,6,-10,0)

The output will be:

PYTHON
16
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

type()

We will create the variables of multiple types and check their types using the type function.

PYTHON
1var1 = 5
2var2 = "Minahil"
3var3 = True
4var4 = 0.6
5var5 = 4j

Using the type() function:

PYTHON
1print(type(var1))
2print(type(var2))
3print(type(var3))
4print(type(var4))
5print(type(var5))

The output will be:

PYTHON
1<class 'int'>
2<class 'str'>
3<class 'bool'>
4<class 'float'>
5<class 'complex'>
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

isinstance()

The function isinstance() accepts two parameters. One is a value and the other is a data type. It then checks if the value passed is of the given data type. Let's see how it works.

PYTHON
1print(isinstance(6, int))
2print(isinstance(6, str))
3print(isinstance(3j, complex))

The output will be:

PYTHON
1True
2False
3True
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Build your intuition. Is this statement true or false?

A list comprehension is more efficient in performance than a loop.

Press true if you believe the statement is correct, or false otherwise.

What are Dict and List Comprehensions?

The comprehensions in Python are simple ways to create a new object from an existing object. There are several of these, including list, dict, set, and nested comprehensions. Let's focus on dict and list comprehensions.

We know that a dictionary is used to store sorted data. It utilizes keys and values (instead of indices and values like a list). Similar to how we have a specific index for a value in a list, we'll have a specific key for each value in the dictionary.

PYTHON
1first_dictionary = {
2    "key1": "value1",
3    "key2": "value2",
4    "key3": "value3",
5    "key4": "value4",
6}

The above dictionary contains four keys and four values. A key can be any number or string, and should be unique. The syntax of dict comprehension is:

PYTHON
1dict_name = {key: value for (key, value) in oldDict.items()}

Now, we will create a new dictionary from first_dictionary. We won't create a duplicate dictionary, but we'll add some values to its existing value.

PYTHON
1new_dictionary = {key: value + " new" for (key, value) in first_dictionary.items()}

This will generate the following dictionary:

PYTHON
1{"key1": "value1 new", "key2": "value2 new", "key3": "value3 new", "key4": "value4 new"}

We can accomplish this task using a loop, but it's more expensive. We can also pass any condition into comprehensions.

List Comprehensions

A list comprehension has the same functionality as dict comprehensions, but is for lists. A list has a specific index for each value. For example, look at the following list of flowers:

PYTHON
1flowers = ["Tulip", "Jasmine", "Rose", "Lili", "Daisy"]

If you wanted to create a new list that contains new flowers, you could use a comprehension instead of a loop. The list comprehension has the following syntax:

PYTHON
1list_name = [expression for variable in old_list condition]

Let's create a new list using the flowers one:

PYTHON
1new_flowers = ["new" + flower for flower in flowers]

The output will be a new list as follows:

PYTHON
1["newTulip", "newJasmine", "newRose", "newLili", "newDaisy"]
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Are you sure you're getting this? Fill in the missing part by typing it in.

The object on which an operator is invoked against is called an ____.

Write the missing line below.

Are there operators in Python other than arithmetic and logical operators?

Yes, there are operators in Python other than arithmetic and logical ones. The others are comparison, identity, membership, and assignment operators. Each type of operators contains multiple operators. Let's have a look at each one by one.

Comparison Operators

These operators are used for the comparison between two values. These are following:

OperatorHow to useFunction
==value1 == value2Checks if value1 is equal to value2
>value1 > value2Checks if value1 is greater than value2
<value1 < value2Checks if value1 is less than value2
>=value1 >= value2Checks if value1 is greater than and equal to value2
<=value1 <= value2Checks if value1 is less than and equal to value2
<>value1 <> value2Checks if value1 is not equal to value2
!=value1 != value2Checks if value1 is not equal to value2

Identity Operators

These operators are used to compare the identity of the variables or type of the variables.

OperatorsHow to useFunction
isvalue1 is value2Checks if both the objects refer to the same object
is notvalue1 is not value2Checks if both the objects do not refer to the same object

Membership Operators

These operators are used to check the membership of a variable in a sequence like lists, strings, etc.

OperatorsHow to useFunction
invalue1 in anySequenceIf used with a condition, it checks if a value is present in a sequence. If used with a for loop, it creates value1 variable and assign sequence values to it one by one.
not invalue1 not in anySequenceIf used with a condition, it checks if a value is not present in a sequence.

Assignment Operators

These operators are used to assign a value to a variable. The main assignment operator is =. It can be used with the arithmetic operators.

OperatorsHow to useFunction
=value1 = value2It updates the value of value1 and assigns value2 to it.
+=value1 += value2It adds the value1 and value2 and assigns the new value to value1
-=value1 -= value2It subtracts value2 from value1 and assigns the new value to value1
*=value1 *= value2It multiplies value1 and value2 and assigns the new value to value1
/=value1 /= value2It divides value1 by value2 and assigns the new value to value1
%=value1 %= value2It takes the modulus of value1 and value2 and assigns the new value to value1

Are you sure you're getting this? Click the correct answer from the options.

Which of the functions are the part of the iterator protocol?

Click the option that best answers the question.

  • print()
  • next()
  • iter()
  • Both next() & iter()

Explain the use of iterators and their importance

An iterator is an object that can be "traversed" through. In other words, it is an object that can be accessed in iterations in place of the full object.

In Python, an iterator is any object that implements the iterator protocol. The protocol contains two built-in functions (iter() and next()). A list is a built-in iterator in python. However, to invoke next(), we would still need to convert it to an iterator object using the iter() method.

PYTHON
1newList = [1, 2, 3, 4, 5]
2next(newList)

The output will be the following error:

Iterators and Their Importance

This is because it is not fully implementing the iterator protocol.

PYTHON
1newList = [1, 2, 3, 4, 5]
2object = iter(newList)
3next(object)

Now that it's fully implementing the protocol, our output will be:

PYTHON
11
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Try this exercise. Is this statement true or false?

A generator is a function.

Press true if you believe the statement is correct, or false otherwise.

What are generators?

A generator is a function used to create iterator objects. it returns an object that can only be used with the for-in loop or next() methods.

But how does the compiler know that something is a generator? There's a special keyword yield for them. Whenever you see a yield keyword inside a function, we know that it is a generator.

Now let's see how a generator works. We can create a simple one:

PYTHON
1def simpleGenerator():
2    yield "a"
3    yield "b"
4    yield "c"
5    yield "d"

Now, if we call this function, it will return an iterator object.

PYTHON
1object = simpleGenerator()

If we try to access this object by using the print() function, it will generate the following output:

PYTHON
1print(object)

The output is:

PYTHON
1<generator object simpleGenerator at 0x0000017884AF2AC8>

We can only access this object using a for-in loop or the next() function.

PYTHON
1for value in simpleGenerator():
2    print(value)

The output will be our iterator object:

PYTHON
1a
2b
3c
4d

We can now use next() function, but it won't display the entire object. For example, look at the following code and its output:

PYTHON
1object = simpleGenerator()
2next(object)

The output will be:

PYTHON
1'a'

It has only shown the first yield value.

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Try this exercise. Fill in the missing part by typing it in.

Object Oriented Programming leans on the idea of classes and ____.

Write the missing line below.

What are the main features of OOP when used in Python?

Object Oriented Programming (OOP) in Python isn't much different than in other languages. It has the same major ideas with a different syntax.

We still use the following big concepts:

  • Classes and objects
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Abstraction

The above mentioned are the main ideas of traditional OOP as well. A class in Python is defined using the keyword class. Similarly, objects are the instances of a class.

Inheritance in OOP is similar to genetic inheritance in real life. The classes assume or take over characteristics from a parent class. We have four types of this in Python:

  1. Single inheritance
  2. Multiple inheritance
  3. Multilevel inheritance
  4. Hierarchical inheritance

The figure below will give you a basic idea of each type.

Other OOP Concepts

Encapsulation is a process in which we enclose our values. We gather all the data and methods at one place.

Polymorphism is a process that defines multiple ways to perform a single action. It is a property of the object that allows it to take multiple forms. There are two types of polymorphism in Python:

  1. Run-time polymorphism
  2. Compile-time polymorphism

Abstraction is a when we hide system details or complexities from end users. When we create an abstract class, it can't have any objects. This class just provides functions for other classes to inherit.

Build your intuition. Is this statement true or false?

A decorator can be added inside a function.

Press true if you believe the statement is correct, or false otherwise.

What is a decorator in Python?

Python offers a unique feature called decorators.

Let's start with an analogy before getting to the technical definition of the decorators. When we mention the word "decorator", what enters your mind? Well, likely something that adds beauty to an existing object. An example is when we hang a picture frame to a wall to enhance the room.

Decorators in Python add some feature or functionality to an existing function without altering it.

Let's say we have the following simple function that takes two numbers as parameters and divides them.

PYTHON
1def divide(first, second):
2    print ("The result is:", first/second)

Now if we call this function by passing the two values 16 and 4, it will return the following output:

PYTHON
1divide(16, 4)

The output is:

PYTHON
1The result is: 4.0
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

What will happen if we pass the number 4 first, and 16 after? The answer will be 0.25. But we don't want it to happen. We want a scenario where if we see that first < second, we swap the numbers and divide them. But we aren't allowed to change the function.

Let's create a decorator that will take the function as a parameter. This decorator will add the swipe functionality to our function.

PYTHON
1def swipe_decorator(func):
2    def swipe(first, second):
3        if first < second:
4            first, second = second, first
5        return func(first, second)
6
7    return swipe

Now we have generated a decorator for the divide() function. Let's see how it works.

PYTHON
1divide = swipe_decorator(divide)
2divide(4, 16)

The output is:

PYTHON
1The result is: 4.0

We have passed the function as a parameter to the decorator. The decorator "swiped our values" and returned the function with swiped values. After that, we invoked the returned function to generate the output as expected.

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

What are Data Structures in Python?

Data structures are the fundamental constructs around which you build your programs. Let's look at the 4 most common types, List,Tuple,Set and Dictionary.

We can compare these structure on the following five characteristics:

  • Mutable: We can change, add , and remove items in the structure after it has been created.
  • Ordered: The items in the structure have a defined order that will not change. If you add new items they will be placed at the end of the structure.
  • Duplicates: Allows items with the same value.
  • Different Objects: Allows objects of different data types.

Data Structures

When Should I use a Dictionary as a Data Structure?

As we seen from before a Dictionary is a structure that stores key-value pairs. We would use this structure in the following scenarios:

  • Quick access to a data point (value), since the data points are uniquely associated with labels (key)
  • When the order of the data points is irrelevant.

How is Memory Stored and Retrieved in a Python Dictionary?

Python's Dictionary is implemented using hash tables. This table is made up of three parts:

  • Hash ID
  • Keys
  • Values

Because of this concept, Python's dictionary is a useful data structure for quickly retrieving relevant value by calling the key. Let's consider the following Python dictionary example where the key is the piece of clothing, and the value is the price:

PYTHON
1clothes_price = {'dress':29.99, 'shoes':19.99, 'shirt': 19.99, 'shorts':14.99}
2
3clothes_price['dress']

By using the square bracket, we can retrieve the value of a specific key giving the following output:

PYTHON
129.99

When Sorting a List What is the Difference Between sorted() and .sort()?

To see the difference, let's illustrate with an example.

PYTHON
1# Our list
2my_list = [2,9,1,6,2,5]
  • sorted
PYTHON
1sort_method_1 = sorted(my_list)
2print('Sorted List 1: ', sort_method_1, 'Old List: ', my_list)

We get the following output:

PYTHON
1Sorted List:  [1, 2, 2, 5, 6, 9] Old List:  [2, 9, 1, 6, 2, 5]
  • .sort()
PYTHON
1sort_method_2 = sort_example.sort()
2print('Sorted List 2: ', sort_method_2, 'Old List: ', my_list)

We get the following output:

PYTHON
1Sorted List 2:  None Old List:  [1, 2, 2, 5, 6, 9]

As demonstrated above sorted() creates another list that is sorted whereas .sort() changes our original list my_list instead of creating another.

Are you sure you're getting this? Click the correct answer from the options.

Which one of the following data structures is immutable?

Click the option that best answers the question.

  • List
  • Tuple
  • Set
  • Dictionary

What is Slicing?

Is the way to access a part of a List, String, or Tuple.

We use ObjectName[start:stop:step] to slice where:

  • Start: specifies the starting element of a slice (included)
  • Stop: specifies the ending element of a slice (not included)
  • Step: (optional) specifies the increment between each index for slicing, default to one if not provided

Let's demonstrate with a list:

PYTHON
1# Our list
2my_list = ['Carl Cox', 'Fred again..', 'Sonny Fodera', 'MK', 'Denis Sulta','Boots & Kats']
  • Positive Slicing
PYTHON
1my_list[1:4:1] # can also be written as my_list[1:4]

Slicing

Let's add a step size.

PYTHON
1my_listmy_list[0:5:2]

Slicing

  • Negative Slicing
PYTHON
1my_list[-1:-4:-1]

Slicing

Again, let's add a step size.

PYTHON
1my_list[-1:-6:-3]

Slicing

Are you sure you're getting this? Is this statement true or false?

The Stop index is inclusive in slicing.

Press true if you believe the statement is correct, or false otherwise.

Sample Glassdoor Python Interview Questions

Now let's look at some questions based off Python Interview Questions from Glassdoor.

Level: Easy

After the success of Black Friday in the Cosmetics department at El Corte Inglés you've been asked to see what employee had the highest sales.

The dataset below is given, with employees by department and their sales. Find the Employee's ID, name and sales.

Coding Questions

PYTHON
1import pandas as pd
2import numpy as np
3
4# Filter to Cosmetics Department
5cosmetic_department = department_sales[department_sales['department'] == 'Cosmetics']
6
7# Create a rank
8cosmetic_department['rank'] = cosmetic_department['sales'].rank(method='min', ascending=False)
9top_employee = cosmetic_department[cosmetic_department['rank'] == 1][['emp_id','first_name','sales']]
10
11top_employee

Coding Questions

So, congratulations to John who'll be receiving a bonus reward for his efforts.

Level: Medium

The team at El Corte Inglés now want to find the employee with the lowest sales over Black Friday, and where they are based so HR can assess their overall capacity for the role.

You've been given an additional dataset, which refers back to the previously given dataset. Find the Employee's ID, name and sales.

Coding Questions

PYTHON
1import pandas as pd
2import numpy as np
3
4# Merge the datasets
5merged_df =  pd.merge(department_sales, emp_location, on='emp_id')
6
7# Find the minimum value
8min_sales = merged_df[merged_df['sales'] == merged_df['sales'].min()][['emp_id','first_name','emp_store']]
9
10min_sales

Coding Questions

Level: Hard

The team at Zara are reviewing their customers' transactions, and you have been tasked with locating the customer who has the third highest total transaction amount.

You've been given two datasets, with information on customers called customers and card_orders with information on card orders placed. Find the Customers ID, and total purchases.

Coding Questions

Coding Questions

PYTHON
1import pandas as pd
2# Merge the datasets
3merged = pd.merge(
4        customers, card_orders, left_on="id", right_on="cust_id", how="inner")
5
6# Get total purchases by customer id
7merged = merged.groupby(["cust_id"])["total_order_cost"].sum().to_frame('total')
8
9# Use rank function to get third customer
10merged["rank"] = merged["total"].rank(method='dense', ascending=False)
11result = merged[merged["rank"] == 3]
12result

Coding Questions

As you can see in this question we have a tie for third place, hence we use a .rank() function. If we used the .head() our answer would have been only half correct.

One Pager Cheat Sheet

  • Python is an easy-to-read, open-source language that works on many operating systems, and has multiple applications ranging from website development to machine learning.
  • Namespaces in Python are implemented as dictionaries, providing an efficient data structure for mapping variables and their values to ensure no naming collisions occur.
  • Namespaces in Python are containers that hold objects and their names as keys and values respectively, with each function, module, or library having its own unique namespace.
  • Objects in Python have specific data types which determine what kinds of information they store and how they behave when used or manipulated.
  • Python offers a wide variety of data types to handle data, including numeric, text, and Boolean.
  • Python int, float, and complex data types are used to represent numeric information.
  • Strings, defined using ' ' or " ", are a type of text data that can include any number, word, sentence, or special character.
  • In Python, boolean data is of class 'bool' and has either a True or False value.
  • We need to invoke or call a function to execute it, which is usually represented by the function's name followed by parenthesis ().
  • The most commonly used built-in functions in Python are print(), len(), min(), max(), type(), and isinstance().
  • The print() function can be used to output strings, variables, and even literal values like integers and booleans.
  • We can use the len() function to find the length of a string, list, tuple, and dictionary.
  • The min() function finds the minimum value of a string, list, tuple, dictionary or multiple values passed as a parameter, resulting in -10 when multiple values are passed.
  • The max() function finds the maximum value of a string, list, tuple, dictionary, or of multiple values passed to it as parameters.
  • We can create different variables and check their types using the type() function.
  • The isinstance() function checks if a given value is of a specific data type.
  • List comprehensions are an efficient and effective way to loop and filter through data, requiring fewer lines of code and often being more computationally efficient.
  • Dict and List Comprehensions are concise ways of creating new objects from existing ones, utilizing keys and values for dictionaries and indices and values for lists.
  • List Comprehensions allow for quickly creating a new list from an existing one using the expression for each variable within the list that meets certain conditions.
  • An operand is the object that an operator is applied to.
  • Yes, Python has multiple types of operators such as comparison, identity, membership, and assignment which can be used for different purposes.
  • An object is iterable when it implements the iterator protocol which consists of the iter() and next() methods for initializing the iterator and calling the next item, respectively, and raising the StopIteration exception when the final item is reached.
  • Iterators encapsulate the iteration process and are essential to accessing objects in Python.
  • Yes, a generator is a function that returns an iterator and can yield a sequence of values without storing them in memory.
  • A generator is a special type of function marked by the yield keyword, which returns an iterator object that can only be used with the for-in loop or next() methods.
  • Object Oriented Programming (OOP) relies heavily on classes and objects, which serve as blueprints that describe the attributes, behaviors, and construction of a real-life object that can be created and have its methods and attributes accessed.
  • OOP in Python utilizes traditional concepts such as classes, objects, inheritance, encapsulation, polymorphism, and abstraction, just with a different syntax.
  • Inheritance, Encapsulation, Polymorphism, and Abstraction are all key principles of Object Oriented Programming that allow developers to create organized, extensible, and powerful software.
  • Decorators can be used to add functionality to a function by being wrapped around it.
  • Decorators in Python can be used to add some feature or functionality to an existing function without altering it, like hanging a picture frame to enhance a room.
  • We have used a swipe_decorator() to add the functionality to our divide() function so that it swaps the values before they get divided if first < second.
  • Data Structures in Python are Mutable, Ordered, allow for Duplicates and Different Objects and can be used for quickly retrieving relevant data with unique labels by using a Dictionary, and the difference between sorted() and .sort() is that sorted() creates another list that is sorted whereas .sort() changes our original list.
  • A Tuple is an immutable data structure that does not allow for changes to be made after it is created.
  • Slicing is a way of programatically accessing parts of Lists, Strings, and Tuples by using ObjectName[start:stop:step].
  • In slicing, the Stop index is not inclusive of the element at the specified index, which can be demonstrated by looking at the result of my_list[1:4] and my_list[-1:-4:-1].
  • This article explores the use of Python (with import pandas and numpy) to solve Glassdoor interview questions related to aggregating data and working with datasets.