Day 4 Python

harichselvamc
1 min readJan 6, 2023

--

Day 4/20

On day 4 of your Python learning journey, you should continue solving exercises on HackerRank to get more practice with the language. You can also start working on a small project of your own using the skills you have learned so far.

Here are a few examples of concepts you might encounter on day 4, along with some code snippets that demonstrate how they work:

Object-oriented programming:

class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed

def bark(self):
print("Woof!")

dog1 = Dog("Fido", "Labrador")
print(dog1.name) # "Fido"
dog1.bark() # prints "Woof!"

Regular expressions:

import re

pattern = r"\d+"

string = "There are 3 dogs."

matches = re.findall(pattern, string)
print(matches) # ["3"]

Working with data:

# reading a CSV file
import csv

with open("data.csv", "r") as f:
reader = csv.reader(f)
rows = list(reader)

print(rows) # [['a', 'b', 'c'], ['1', '2', '3']]

# writing to a CSV file
import csv

data = [["a", "b", "c"], ["1", "2", "3"]]

with open("data.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(data)

I hope that these Python Preparation Plans will help you enhance your interest in programming as well as python and then all python topics. Please feel free to provide insightful remarks in the space below.

20days-python-plans

--

--

harichselvamc

I am a quick learner with a good eye for detail. I am also an exceptional coder with a great work ethic.