🐍 𝐃𝐚𝐲 𝟖 (𝐄𝐯𝐞𝐧𝐢𝐧𝐠) 𝐨𝐟 𝐌𝐲 𝟏𝟓-𝐃𝐚𝐲 𝐏𝐲𝐭𝐡𝐨𝐧 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 — 𝐃𝐚𝐭𝐞 & 𝐓𝐢𝐦𝐞 𝐇𝐚𝐧𝐝𝐥𝐢𝐧𝐠 In today’s evening session, I focused on date and time handling — a critical skill for logging, analytics, scheduling, and reporting. Python’s datetime module makes working with dates and times straightforward. 🔹 𝐖𝐡𝐚𝐭 𝐈 𝐂𝐨𝐯𝐞𝐫𝐞𝐝 𝐓𝐨𝐝𝐚𝐲 ✅ Getting Current Date & Time from datetime import datetime now = datetime.now() print(now) ✅ Working with Dates from datetime import date today = date.today() print(today) ✅ Formatting Dates formatted = now.strftime("%Y-%m-%d %H:%M:%S") print(formatted) ✅ Date Arithmetic with timedelta from datetime import timedelta future_date = today + timedelta(days=7) print(future_date) ✅ Difference Between Dates start_date = date(2024, 1, 1) end_date = date.today() difference = end_date - start_date print(difference.days) 🎯 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Date and time handling is essential for real-world applications like reports, logs, and automation. Mastering datetime and timedelta makes time-based logic much easier. ✅ Day 8 Completed 𝐓𝐨𝐦𝐨𝐫𝐫𝐨𝐰: 𝐃𝐚𝐲 𝟗 (𝐌𝐨𝐫𝐧𝐢𝐧𝐠) — 𝐎𝐎𝐏 𝐁𝐚𝐬𝐢𝐜𝐬 (𝐂𝐥𝐚𝐬𝐬𝐞𝐬 & 𝐎𝐛𝐣𝐞𝐜𝐭𝐬) Let’s keep moving #Python #DateTime #15DaysOfPython #LearningInPublic #Programming
Mastering Date & Time Handling in Python
More Relevant Posts
-
🧠 Python Concept That Feels Like a Hack: frozenset It’s like a set… but unchangeable 🔒 🤔 What Is frozenset? A frozenset is: 💫 Immutable (can’t add/remove items) 💫 Hashable (can be used as a dictionary key) 🧪 Example skills = frozenset(["python", "sql", "git"]) # skills.add("docker") ❌ Error 🧠 Why This Is Special data = { frozenset(["read", "write"]): "User A", frozenset(["read"]): "User B" } Normal set ❌ frozenset ✅ 🧒 Simple Explanation 💻 A set is like a whiteboard ✏️ 💻 You can erase and add. 💻 A frozenset is like a printed poster 🖼️ 💻 You can look… but not change. 💡 When You Should Use It ✔ As dictionary keys ✔ For fixed configurations ✔ When safety matters ✔ Advanced Python design 💫 Python gives you tools for safety, not just speed. 💫 frozenset is one of those features you don’t need every day… until you really do 🐍✨ #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode #FrozenSet
To view or add a comment, sign in
-
-
Working with Integers & Floating-Point Numbers As I continue building strong Python fundamentals, I have been focusing on how numeric data types work specifically integers (int) and floating-point numbers (float). - Integers represent whole numbers, while floats handle decimal values. Python automatically infers the type based on the assigned value. - Practiced core arithmetic operations such as addition, subtraction, multiplication, and division, noting that standard division always returns a float. - Learned that mixing integers and floats in calculations automatically promotes the result to a float. - Explored advanced numeric operations like modulo (%), floor division (//), and exponentiation (**), which are commonly used in analytical computations. - Worked with type conversion using int() and float() to transform numbers and numeric strings into the required formats. - Reviewed helpful built-in functions like round(), abs(), and pow() for rounding, absolute values, and exponentiation. #PythonBasics #NumbersInPython #DataAnalyticsJourney #LearningInPublic #Upskilling
To view or add a comment, sign in
-
Tired of manually tracking indices in your loops? The `enumerate()` function is your secret weapon for cleaner, more Pythonic code! Instead of this: ```python my_list = ["apple", "banana", "cherry"] for i in range(len(my_list)): print(i, my_list[i]) ``` Use this: ```python my_list = ["apple", "banana", "cherry"] for index, value in enumerate(my_list): print(index, value) ``` Benefits of using `enumerate()`: * More readable code, reducing cognitive load. * Less error-prone as you avoid potential off-by-one errors when managing indices manually. * More efficient in some cases, especially with iterators. Do you use `enumerate()` in your Python code? What are some other Pythonic tricks you find indispensable? Share in the comments below! 👇 #Python #Programming #CodeOptimization #DataScience #CodingTips
To view or add a comment, sign in
-
-
Getting Comfortable with Data Types Lately, I have been strengthening my Python fundamentals by understanding how different kinds of data are represented and handled in the language - a key concept when working with real-world data. - Python automatically identifies data types based on assigned values, making it flexible and easy to work with. - Explored commonly used data types such as integers, floats, strings, Booleans, lists, tuples, sets, dictionaries, range, and None. - Learned how to inspect variable types using the built-in type() function. - Also practiced checking data types using isinstance() to avoid unexpected runtime issues. These basics play an important role in writing clean, error-free code and handling data effectively. #PythonLearning #DataTypes #DataAnalyticsJourney #LearningInPublic #Upskilling
To view or add a comment, sign in
-
🐍 𝐃𝐚𝐲 𝟗 (𝐄𝐯𝐞𝐧𝐢𝐧𝐠) 𝐨𝐟 𝐌𝐲 𝟏𝟓-𝐃𝐚𝐲 𝐏𝐲𝐭𝐡𝐨𝐧 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 — 𝐎𝐎𝐏 𝐀𝐝𝐯𝐚𝐧𝐜𝐞𝐝 In today’s evening session, I explored inheritance and polymorphism — two powerful OOP concepts that help build flexible and reusable code. 🔹 𝐖𝐡𝐚𝐭 𝐈 𝐂𝐨𝐯𝐞𝐫𝐞𝐝 𝐓𝐨𝐝𝐚𝐲 ✅ Inheritance Inheritance allows a class to reuse properties and methods of another class. class Employee: def __init__(self, name): self.name = name def role(self): return "Employee" class Developer(Employee): def role(self): return "Developer" ✅ Using Inherited Methods dev = Developer("Ankush") print(dev.name) print(dev.role()) ✅ Polymorphism Polymorphism allows the same method name to behave differently depending on the object. employees = [Employee("Amit"), Developer("Ankush")] for emp in employees: print(emp.role()) Output depends on the object type. ✅ Why It Matters ✔ Reduces code duplication ✔ Improves flexibility ✔ Makes systems easier to extend 🎯 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Inheritance builds relationships between classes. Polymorphism lets objects behave differently using the same interface. Together, they make Python code clean, scalable, and powerful. ✅ Day 9 Completed 𝐓𝐨𝐦𝐨𝐫𝐫𝐨𝐰: 𝐃𝐚𝐲 𝟏𝟎 (𝐌𝐨𝐫𝐧𝐢𝐧𝐠) — 𝐈𝐭𝐞𝐫𝐚𝐭𝐨𝐫𝐬 & 𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐨𝐫𝐬 Let’s keep going #Python #OOP #Inheritance #Polymorphism #15DaysOfPython #LearningInPublic
To view or add a comment, sign in
-
Minitask Session 12 : Basic Python From this session, I learn something about : 1. Writing Structure (Syntax) 2. Data Type Flexibility Like : - String (Text) - Integer (Numbers) - List (Arrays, e.g., ['Coding', 'Data Analysis']) - Boolean (True/False, e.g., True) - Nested Dictionary (A dictionary inside another dictionary, e.g., the personality data). 3. How to retrieve data from a dictionary using key Thanks to Muslar Alibasya as my mentor and MySkill #Dataanalytics #Myskill
To view or add a comment, sign in
-
File handling in Python is less about syntax and more about understanding data flow 📂 In this practice session, I worked through the complete lifecycle of a text file — creating it, reading its contents, appending new data, and then modifying specific lines by re-writing the file. The exercise reinforced how Python’s file modes (w, r, a) directly control data persistence and why careless use of write mode can overwrite existing content. Reading data as a whole versus line-by-line also highlighted how different approaches suit different use cases. What made this exercise practical was treating the file like real data, not just text. Inserting a line at a specific position required reading into memory, modifying the structure, and writing it back — a common pattern when dealing with logs, reports, or configuration files. This is foundational for handling larger datasets later on, especially when working with data engineering and Big Data workflows 🔄 Understanding file handling at this level builds confidence for working beyond in-memory data. #Python #FileHandling #ProgrammingFundamentals #DataEngineeringBasics #CleanCode #LearningByDoing
To view or add a comment, sign in
-
-
🐍 𝐃𝐚𝐲 𝟏𝟎 (𝐌𝐨𝐫𝐧𝐢𝐧𝐠) 𝐨𝐟 𝐌𝐲 𝟏𝟓-𝐃𝐚𝐲 𝐏𝐲𝐭𝐡𝐨𝐧 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 — 𝐈𝐭𝐞𝐫𝐚𝐭𝐨𝐫𝐬 & 𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐨𝐫𝐬 Today’s morning session was about iterators and generators — powerful tools for working with data efficiently and lazily. They are especially useful when dealing with large datasets. 🔹 𝐖𝐡𝐚𝐭 𝐈 𝐂𝐨𝐯𝐞𝐫𝐞𝐝 𝐓𝐨𝐝𝐚𝐲 ✅ What Is an Iterator? An iterator is an object that returns elements one at a time. numbers = [1, 2, 3] iterator = iter(numbers) print(next(iterator)) print(next(iterator)) ✅ Custom Iterator (Concept) class Counter: def __init__(self, max_value): self.current = 0 self.max = max_value def __iter__(self): return self def __next__(self): if self.current < self.max: self.current += 1 return self.current raise StopIteration ✅ What Is a Generator? Generators use yield to produce values one at a time. def count_up_to(n): for i in range(1, n + 1): yield i ✅ Using a Generator for number in count_up_to(3): print(number) 🎯 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Iterators and generators help handle large data efficiently by saving memory. If you don’t need all values at once — generators are the best choice. 🌆 𝐄𝐯𝐞𝐧𝐢𝐧𝐠 𝐒𝐞𝐬𝐬𝐢𝐨𝐧 (𝐃𝐚𝐲 𝟏𝟎): 𝐃𝐞𝐜𝐨𝐫𝐚𝐭𝐨𝐫𝐬 Let’s keep learning #Python #Iterators #Generators #15DaysOfPython #LearningInPublic #Programming
To view or add a comment, sign in
-
🧠 Python Feature That Makes Functions Smarter: functools.singledispatch 💫 One function. 💫 Multiple behaviors. 💫 No ugly if isinstance() chains 😌 ❌ Old Way def process(data): if isinstance(data, int): return data * 2 elif isinstance(data, str): return data.upper() ✅ Pythonic Way from functools import singledispatch @singledispatch def process(data): raise NotImplementedError @process.register def _(data: int): return data * 2 @process.register def _(data: str): return data.upper() 🧒 Simple Explanation Imagine one teacher 👩🏫 💻 If a number comes → do math 💻 If a word comes → read loudly 💻 Same teacher. 💻 Different rules.. 💡 Why This Is Powerful ✔ Cleaner logic ✔ Easy to extend ✔ Great for APIs & libraries ✔ Real-world Python feature ⚠️ Important Note Dispatch happens on the first argument only. 🐍 Python lets your code decide what to do based on the data. 🐍 singledispatch keeps logic clean and extensible #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 Python Concept That Makes Code Cleaner: enumerate() vs range(len()) Most people still write this 👇 names = ["Asha", "Rahul", "Zoya"] for i in range(len(names)): print(i, names[i]) Works… but it’s not Pythonic 😬 ✅ Pythonic Way for i, name in enumerate(names): print(i, name) Same result. Cleaner. Safer. More readable ✨ 🧒 Simple Explanation Imagine calling roll numbers in class 🧑🏫 Python gives you: the number 🧾 and the name 👤 together — no counting needed. 💡 Why This Matters ✔ Avoids index mistakes ✔ Reads like English ✔ Cleaner loops ✔ Very common interview question ⚡ Bonus Tip Start counting from 1 👇 for i, name in enumerate(names, start=1): print(i, name) 💻 Clean code isn’t about fewer lines. 💻 It’s about clear intent 🐍✨ 💻 If you’re still using range(len()), Python has a better idea. #Python #PythonTips #PythonTricks #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development