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 askeys
andvalues
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, includingnumeric
,text
, andBoolean
. - Python
int
,float
, andcomplex
data types are used to represent numeric information. - Strings, defined using
' '
or" "
, are atype
of text data that can include any number, word, sentence, or special character. - In Python,
boolean
data is ofclass 'bool'
and has either aTrue
orFalse
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
areprint()
,len()
,min()
,max()
,type()
, andisinstance()
. - The
print()
function can be used to output strings, variables, and evenliteral
values likeintegers
andbooleans
. - We can use the
len()
function to find the length of astring
,list
,tuple
, anddictionary
. - The
min()
function finds the minimum value of astring
,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 astring
,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 givenvalue
is of a specificdata type
. - List comprehensions are an efficient and effective way to
loop
andfilter
through data, requiring fewerlines of code
and often being more computationally efficient. - Dict and List Comprehensions are concise ways of creating new objects from existing ones, utilizing
keys
andvalues
for dictionaries andindices
andvalues
for lists. List
Comprehensions allow for quickly creating a newlist
from an existing one using theexpression
for eachvariable
within thelist
that meets certaincondition
s.- An
operand
is the object that an operator is applied to. - Yes, Python has multiple types of operators such as
comparison
,identity
,membership
, andassignment
which can be used for different purposes. - An object is iterable when it implements the iterator protocol which consists of the
iter()
andnext()
methods for initializing the iterator and calling the next item, respectively, and raising theStopIteration
exception when the final item is reached. Iterators
encapsulate
theiteration
process and areessential
to accessing objects in Python.- Yes, a generator is a
function
that returns aniterator
and canyield
a sequence of values without storing them in memory. - A generator is a special type of function marked by the
yield
keyword, which returns aniterator
object that can only be used with thefor-in loop
ornext()
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 asclasses
,objects
,inheritance
,encapsulation
,polymorphism
, andabstraction
, 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, likehanging a picture frame
to enhance aroom
.- We have used a
swipe_decorator()
to add the functionality to ourdivide()
function so that it swaps the values before they get divided iffirst < second
. - Data Structures in Python are
Mutable
,Ordered
, allow forDuplicates
andDifferent Objects
and can be used for quickly retrieving relevant data with unique labels by using aDictionary
, and the difference betweensorted()
and.sort()
is thatsorted()
creates another list that is sorted whereas.sort()
changes our original list. - A
Tuple
is animmutable
data structure that does not allow for changes to be made after it is created. Slicing
is a way of programatically accessing parts ofLists
,Strings
, andTuples
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 ofmy_list[1:4]
andmy_list[-1:-4:-1]
. - This article explores the use of
Python
(withimport pandas
andnumpy
) to solveGlassdoor
interview questions related to aggregating data and working with datasets.