Skip to main content

Command Palette

Search for a command to run...

Week 3 as an intern

Updated
2 min read

Week 3 At Datara Flow

This week in datara flow python class, we covered some new and interesting topics. At first, they looked difficult, but with practice, I started to understand how they work. Below is a summary of what I learnt;

1)Modules
Modules are like extra toolboxes in Python. Instead of writing every code by ourselves, we can just import a module and use its functions. For example, the math module allows us to do advanced calculations.
import math
print(math.sqrt(25)) # Output: 5.0

2)Dates and Time
Python can also work with dates. With the datetime module, we can check today’s date and even format it in different ways.
import datetime
today = datetime.datetime.now()
print(today.strftime("%Y-%m-%d"))
3)Mathematics
Apart from normal calculations like +, -, *, and /, Python gives us more math functions inside the math module.
import math
print(math.factorial(5)) # 120
print(math.pi) # 3.14159...

4) JSON
I also learned about JSON, which is a way of storing data. It looks like a Python dictionary and is mostly used when working with data from the internet.
import json
student = {"name": "Amina", "age": 25}
data = json.dumps(student)
print(data)
5) Pip, Error Handling, and User Input

pip is a tool to install external Python libraries.
try...except helps to handle errors so that the program doesn’t crash.
input() allows the user to type something into the program.
Example of error handling:
try:
x = int("hello")
except:
print("An error occurred")
6) Reading and Writing Files
Python can also read from files and write to them. This means we can store information and bring it back later.
f = open("notes.txt", "w")
f.write("This is my Week 3 Python learning")
f.close()

The take home tasks were basically to practice everything we learned this week:

Create and use a module.
Work with today’s date.
Try out math functions.
Convert a dictionary to JSON.
Handle an error with try...except.
Save something in a file and read it back.

Week 3 was full of practical lessons. I realized that python is not just about printing “Hello World”, but it can actually handle files, time, errors, and even external libraries. I am slowly getting comfortable with these concepts, and I know with more practice they will become easiest.