🚀
Python Crash Course
01 Python Crash Course
++++
Data Science
May 2026×Notebook lesson

Notebook converted from Jupyter for blog publishing.

01-Python Crash Course

Driptanil Datta
Driptanil DattaSoftware Developer

Data types

Numbers

1 + 1
RESULT
2
1 * 3
RESULT
3
1 / 2
RESULT
0.5
2 ** 4
RESULT
16
4 % 2
RESULT
0
5 % 2
RESULT
1
(2 + 3) * (5 + 5)
RESULT
50

Variable Assignment

# Can not start with number or special characters
name_of_var = 2
x = 2
y = 3
z = x + y
z
RESULT
5

Strings

'single quotes'
RESULT
'single quotes'
"double quotes"
RESULT
'double quotes'
" wrap lot's of other quotes"
RESULT
" wrap lot's of other quotes"

Printing

x = 'hello'
x
RESULT
'hello'
print(x)
STDOUT
hello
num = 12
name = 'Sam'
print('My number is: {one}, and my name is: {two}'.format(one=num,two=name))
STDOUT
My number is: 12, and my name is: Sam
print('My number is: {}, and my name is: {}'.format(num,name))
STDOUT
My number is: 12, and my name is: Sam

Lists

[1,2,3]
RESULT
[1, 2, 3]
['hi',1,[1,2]]
RESULT
['hi', 1, [1, 2]]
my_list = ['a','b','c']
my_list.append('d')
my_list
RESULT
['a', 'b', 'c', 'd']
my_list[0]
RESULT
'a'
my_list[1]
RESULT
'b'
my_list[1:]
RESULT
['b', 'c', 'd']
my_list[:1]
RESULT
['a']
my_list[0] = 'NEW'
my_list
RESULT
['NEW', 'b', 'c', 'd']
nest = [1,2,3,[4,5,['target']]]
nest[3]
RESULT
[4, 5, ['target']]
nest[3][2]
RESULT
['target']
nest[3][2][0]
RESULT
'target'

Dictionaries

d = {'key1':'item1','key2':'item2'}
d
RESULT
{'key1': 'item1', 'key2': 'item2'}
d['key1']
RESULT
'item1'

Booleans

True
RESULT
True
False
RESULT
False

Tuples

t = (1,2,3)
t[0]
RESULT
1
t[0] = 'NEW'
ERROR
MORE
TypeError: 'tuple' object does not support item assignment
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-97e4e33b36c2> in <module>()
----> 1 t[0] = 'NEW'

Sets

{1,2,3}
RESULT
{1, 2, 3}
{1,2,3,1,2,1,2,3,3,3,3,2,2,2,1,1,2}
RESULT
{1, 2, 3}

Comparison Operators

1 > 2
RESULT
False
1 < 2
RESULT
True
1 >= 1
RESULT
True
1 <= 4
RESULT
True
1 == 1
RESULT
True
'hi' == 'bye'
RESULT
False

Logic Operators

(1 > 2) and (2 < 3)
RESULT
False
(1 > 2) or (2 < 3)
RESULT
True
(1 == 2) or (2 == 3) or (4 == 4)
RESULT
True

if,elif, else Statements

if 1 < 2:
    print('Yep!')
STDOUT
Yep!
if 1 < 2:
    print('yep!')
STDOUT
yep!
if 1 < 2:
    print('first')
else:
    print('last')
STDOUT
first
if 1 > 2:
    print('first')
else:
    print('last')
STDOUT
last
if 1 == 2:
    print('first')
elif 3 == 3:
    print('middle')
else:
    print('Last')
STDOUT
middle

for Loops

seq = [1,2,3,4,5]
for item in seq:
    print(item)
STDOUT
1
2
3
4
5
for item in seq:
    print('Yep')
STDOUT
Yep
Yep
Yep
Yep
Yep
for jelly in seq:
    print(jelly+jelly)
STDOUT
2
4
6
8
10

while Loops

i = 1
while i < 5:
    print('i is: {}'.format(i))
    i = i+1
STDOUT
i is: 1
i is: 2
i is: 3
i is: 4

range()

range(5)
RESULT
range(0, 5)
for i in range(5):
    print(i)
STDOUT
0
1
2
3
4
list(range(5))
RESULT
[0, 1, 2, 3, 4]

list comprehension

x = [1,2,3,4]
out = []
for item in x:
    out.append(item**2)
print(out)
STDOUT
[1, 4, 9, 16]
[item**2 for item in x]
RESULT
[1, 4, 9, 16]

functions

def my_func(param1='default'):
    """
    Docstring goes here.
    """
    print(param1)
my_func
RESULT
<function __main__.my_func>
my_func()
STDOUT
default
my_func('new param')
STDOUT
new param
my_func(param1='new param')
STDOUT
new param
def square(x):
    return x**2
out = square(2)
print(out)
STDOUT
4

lambda expressions

def times2(var):
    return var*2
times2(2)
RESULT
4
lambda var: var*2
RESULT
<function __main__.<lambda>>

map and filter

seq = [1,2,3,4,5]
map(times2,seq)
RESULT
<map at 0x105316748>
list(map(times2,seq))
RESULT
[2, 4, 6, 8, 10]
list(map(lambda var: var*2,seq))
RESULT
[2, 4, 6, 8, 10]
filter(lambda item: item%2 == 0,seq)
RESULT
<filter at 0x105316ac8>
list(filter(lambda item: item%2 == 0,seq))
RESULT
[2, 4]

methods

st = 'hello my name is Sam'
st.lower()
RESULT
'hello my name is sam'
st.upper()
RESULT
'HELLO MY NAME IS SAM'
st.split()
RESULT
['hello', 'my', 'name', 'is', 'Sam']
tweet = 'Go Sports! #Sports'
tweet.split('#')
RESULT
['Go Sports! ', 'Sports']
tweet.split('#')[1]
RESULT
'Sports'
d
RESULT
{'key1': 'item1', 'key2': 'item2'}
d.keys()
RESULT
dict_keys(['key2', 'key1'])
d.items()
RESULT
dict_items([('key2', 'item2'), ('key1', 'item1')])
lst = [1,2,3]
lst.pop()
RESULT
3
lst
RESULT
[1, 2]
'x' in [1,2,3]
RESULT
False
'x' in ['x','y','z']
RESULT
True

Great Job!

Drip

Driptanil Datta

Software Developer

Building full-stack systems, one commit at a time. This blog is a centralized learning archive for developers.

Legal Notes
Disclaimer

The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP

Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

© 2026 Driptanil Datta. All rights reserved.