🚀 Beginner Python Project: Fetch Weather Data Using an API Today I built a small Python script that gets the last 7 days of weather data using a free weather API. This project helped me understand APIs, date handling, and JSON data in Python. Step 1 – Import libraries requests lets Python send requests to websites, and datetime helps us work with dates. Step 2 – Calculate dates The script gets today’s date, then calculates yesterday and 7 days ago. We use yesterday because some weather APIs don’t allow today's data. Step 3 – Format dates Dates are converted to YYYY-MM-DD format so the API can understand them. Step 4 – Set location Latitude and longitude coordinates are used to specify a location (in this case, Paris). Step 5 – Create the API request Python builds a URL that includes: • Location • Start date • End date • Max & min daily temperatures Step 6 – Send the request requests.get() sends the request to the API and receives weather data. Step 7 – Convert API response The response is converted into JSON, which works like a Python dictionary. Step 8 – Print the result Finally, the program prints the weather data for the last 7 days. Small projects like this are a great way to learn how real-world applications collect data from APIs. I’m currently learning Python, AI, and real-world coding projects, and sharing my progress publicly. Let’s connect if you're on the same journey! 🚀 #Python #PythonProjects #API #WeatherAPI #CodingForBeginners #LearnPython #AIJourney
Python Weather API Project: Fetching 7-Day Data
More Relevant Posts
-
Python Tip Every Beginner Should Know One concept that saves you from many bugs in Python Mutable vs Immutable Objects In Python, some objects can change after creation, while others cannot. 🔹 Immutable Objects (cannot change) Examples: int, float, string, tuple x = 10 x = x + 5 print(x) Here Python creates a new object instead of modifying the original one. Another example: name = "Python" name[0] = "J" # Error Strings are immutable, so their values cannot be changed. 🔹 Mutable Objects (can change) Examples: list, dictionary, set numbers = [1, 2, 3] numbers.append(4) print(numbers) Output: [1, 2, 3, 4] Here the same list object is modified. 💡 Why this matters? If you pass a list to a function, the original data can change. def add_item(lst): lst.append(100) data = [1, 2, 3] add_item(data) print(data) Output: [1, 2, 3, 100] Understanding this concept helps a lot in: ✔ Data Analysis ✔ Machine Learning ✔ Writing clean Python code 📌 Tip: If you want to avoid modifying the original list: new_list = old_list.copy() Small Python concepts like this make a big difference in writing better code. If you're learning Python, remember this: Mutable → Can change Immutable → Cannot change If you're learning Python, mastering small concepts like this makes a big difference. #Python #PythonProgramming #Coding #DataScience #LearnPython #ProgrammingTips #DataAnalyst
To view or add a comment, sign in
-
💡How self Works in Python Classes In Python, we can create a class and then create objects (instances) from that class. When we call a method using an object, self refers to the object that invoked the method. 🔹Example class Person: def say_name(self, name): print("My name is", name) p1 = Person() p2 = Person() p1.say_name("Ahmed") p2.say_name("Mohamed") ➡️ Output My name is Ahmed My name is Mohamed 🔹Execution Steps 1️⃣ We created a class called Person. 2️⃣ Inside the class, we defined a method called say_name, which takes two parameters: • self • name 3️⃣ Then we created two objects (instances) from the class: • p1 • p2 4️⃣ When we write: p1.say_name("Ahmed") Python internally interprets it as: Person.say_name(p1, "Ahmed") So: self = p1 name = "Ahmed" ➡️ The method prints: My name is Ahmed 5️⃣ When we write: p2.say_name("Mohamed") Python interprets it as: Person.say_name(p2, "Mohamed") So: self = p2 name = "Mohamed" ➡️ The method prints: My name is Mohamed 🔹 Main Idea When we call a method using an object: object.method() self automatically refers to the object that called the method. This allows the method to know which instance it is currently working with, so it can access and work with that object’s data. #Python #PythonProgramming #OOP #LearnPython #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
📢 Day 2 of my Python series is LIVE on MrCloudBook! 🐍 𝗣𝘆𝘁𝗵𝗼𝗻 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 & 𝗘𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝗼𝗻𝘀 — the building blocks that make your variables actually DO something! In Day 1, we covered variables and data types — the nouns of Python. Day 2 is all about the verbs. ✅ Here's what's inside: 🔢 Arithmetic operators — including the 3 that surprise every beginner: //, %, ** 🔍 Comparison operators — and the classic = vs == trap 🧠 Logical operators — and, or, not (with short-circuit evaluation!) ✅ Truthiness — what Python considers True or False 📝 Assignment operators — +=, -=, *= and more 🔤 String operators — +, *, and in 🎯 Operator precedence — so your expressions mean what you think they mean 💼 A complete Invoice Calculator project using every concept from the article If you're starting your Python journey or know someone who is — this one's for you. 🙌 👇 Read it here: https://lnkd.in/gSqznx_T #Python #LearnPython #PythonForBeginners #MrCloudBook #DevOps #100DaysOfCode #Programming #TechCommunity
To view or add a comment, sign in
-
🔹 Understanding Python Memory One important concept is how Python stores data in memory. When we write: a = 10 Most people think variable a stores the value 10. But in reality, Python variables store references to objects. Here 10 is the object, and a simply points to that object in memory. Multiple variables can reference the same object: a = 10 b = a Both a and b point to the same object in memory. 🔹 Mutable vs Immutable Objects Understanding this difference is very important in backend development. Immutable objects (cannot change after creation) ✴️ int ✴️ float ✴️ bool ✴️ str ✴️ tuple Example: a = 10 a = 20 Python creates a new object instead of modifying the old one. Mutable objects (can change after creation) ✴️ list ✴️ dictionary ✴️ set ✴️ custom classes Example: a = [1, 2] b = a b.append(3) Now a becomes: [1, 2, 3] Because both variables point to the same mutable object. This is a very common source of bugs in backend systems when shared state is not handled properly. 🔹 Generators in Python Generators are extremely useful for handling large data efficiently. A generator produces values one at a time instead of loading everything into memory. Example: def numbers(): for i in range(5): yield i for n in numbers(): print(n) Here, values are generated only when needed. 💡 Why generators are important in backend systems Generators are widely used for: ✴️ Streaming large API responses ✴️ Processing logs ✴️ Reading millions of database rows ✴️ Background workers ✴️ Data pipelines ✴️ Async streaming They help save memory and improve performance, especially when working with large datasets. #Python #BackendEngineering #SoftwareDevelopment
To view or add a comment, sign in
-
Python raises no error and produces no warning when an instance attribute shadows a @classmethod. The method is still on the class — it's just hidden from that specific instance. This happens because @classmethod is a non-data descriptor. It defines __get__ but not __set__, which puts it in tier 3 of Python's three-tier attribute lookup. An instance attribute with the same name sits in tier 2 (the instance __dict__) and wins every time. The result: c.create() raises TypeError with a message that never mentions shadowing. The bug can sit undetected for a long time. A new article on PythonCodeCrack covers how the descriptor protocol makes this possible, how to detect an active shadow using vars() and an MRO walk, and six prevention strategies — from naming conventions and __slots__ to ProtectedClassMethod data descriptors and a ProtectedMeta metaclass for hierarchy-wide coverage. There's also an interactive step-through visualizer, a Spot the Bug challenge, and a decision flowchart that routes to the right prevention strategy based on your codebase constraints. https://lnkd.in/ghRPQF9U #Python #PythonProgramming #SoftwareEngineering #DescriptorProtocol #PythonTips
To view or add a comment, sign in
-
🚀 #python #Ep 2: Understanding #Data Types in Python In Python, everything is an object, and every object has a data type. Data types define what kind of value a variable holds and what operations you can perform on it. 🔗 Code reference: https://lnkd.in/ei6STRqT 🧠 Why Data Types Matter? Prevent errors in your code Help Python understand how to store and process data Make your programs efficient and readable 📌 Common Python Data Types 🔢 Numeric Types int → Whole numbers (10, -5) float → Decimal numbers (3.14) complex → Complex numbers (2+3j) 📝 String (str) Used to store text Example: "Hello Python" ✅ Boolean (bool) Only two values: True or False 📦 Sequence Types list → Ordered & mutable → [1, 2, 3] tuple → Ordered & immutable → (1, 2, 3) 🗂️ Mapping Type dict → Key-value pairs → {"name": "Hari"} 🔁 Set Types set → Unordered & unique values → {1, 2, 3} 💡 Pro Tip Python is dynamically typed, meaning you don’t need to declare data types explicitly — Python figures it out at runtime 🔍 Example x = 10 # int y = 3.14 # float name = "Hari" # str is_active = True # bool 📣 Final Thought Mastering data types is the foundation of Python programming. Once you understand them, everything else becomes easier! #Python #Coding
To view or add a comment, sign in
-
-
Machine Learning Graph Data using python igraph #machinelearning #datascience #graphdata #pythonigraph igraph is a fast open source tool to manipulate and analyze graphs or networks. It is primarily written in C. python-igraph is igraph’s interface for the Python programming language. python-graph includes functionality for graph plotting and conversion from/to networkx. Python interface of igraph, a fast and open source C library to manipulate and analyze graphs (aka networks). It can be used to: Create, manipulate, and analyze networks. Convert graphs from/to networkx, graph-tool and many file formats. Plot networks using Cairo, matplotlib, and plotly. https://lnkd.in/gzzzK7eU
To view or add a comment, sign in
-
🚀 Functions vs Generators in Python — Explained the Human Way 😄 Ever wondered why Python has both functions and generators? Let’s break it down with a real‑life example 👨🍳 Imagine You Run a Fancy Café ☕ Scenario 1: Customer orders a coffee. You: “One cappuccino coming right up!” You make the coffee, hand it over, and… you're done. ✔ That's a Function You do the job once, return the result, and move on. def make_coffee(): return "☕ Cappuccino ready!" 🍪 Scenario 2: Customer orders 500 cookies for a party. You could bake all 500 at once… But your kitchen (and your sanity) would explode. 💥 So instead, you bake one batch at a time: Bake Serve Bake Serve Pause Repeat ✔ That's a Generator You produce results one at a time, only when requested. def cookie_generator(batch_size): total = 0 while True: total += batch_size yield total 🧠 Why It Matters 💡 Use a Function when: You need a quick result like: ✔ printing a greeting ✔ calculating a sum ✔ preparing one order 💡 Use a Generator when: You need to handle LOTS of data: ✔ logs ✔ huge files ✔ streaming data ✔ or… 500 cookies 🍪😅 Functions are like that one friend who gives you everything in one go. Generators are like that friend who says: “I’ll give you updates… but only when you ask.” And both of them make Python programming a whole lot sweeter. 🍫🐍 #Python #Coding #LearningPython #SoftwareEngineering #DataScience #TechLearning #PythonDeveloper #CodeNewbies
To view or add a comment, sign in
-
-
Python scripts are way to easy to worry about.. Even for Today I started digging into more of the details on the Beautiful Soup, so what exactly will I need to make a python script work. I started by researching "Python Script" and found a beginner guide on python script. One of the ideas that your suppose to do with python script is the path to where python is, so that it will be able to excite it, once you open it or type the file name in the terminal. I wanted to get a blueprint or outline of what the python script will do exactly, so I made an outline line-by-line of what the main script will do but also more of the details of what the script will look. Once that's done, all I have to do is come up with the code. I am getting alot of the thinking part the script already taken care so that I can execute my plan once its fully on the screen. That's where I left off today, I have a begin outline of the script and have some code parts that I am already working on. If you managed to make it this far, kudos. I haven't uploaded anything yet to GitHub here why, I am focused on building my pipeline in phases. I first want to build the scrip, test it to make sure it works then upload it to GitHub, that way I know for sure it will work if I have to pull changes. #DataAnalyst #DataScientist #Pipeline #Opentowork
To view or add a comment, sign in
-
-
🚀 Python Basics – Ordered Sequence Data Type (Lists) Today, I practiced working with lists in Python. A list is an ordered collection of items, meaning the elements keep their position and can be accessed using indexing. 💻 Example Code: list0 = [1, 2, 3] # List of integers list1 = [1, 2.5, 3] # List with mixed numeric types (int + float) list2 = ['a', 'b'] # List of strings list3 = [True, False] # List of boolean values print(list0) print(list1) print(list2) print(list3) ✅ Key Points: Lists are ordered → items have a fixed position Lists are mutable → you can change, add, or remove elements Lists can store different data types (int, float, string, bool, etc.) Elements are accessed using indexing (e.g., list0[0] → 1) 📌 Example Output: [1, 2, 3] [1, 2.5, 3] ['a', 'b'] [True, False] ✅ Key Points: Lists in Python are ordered sequences of elements. You can access, modify, and slice list items using their index. Lists can store different data types like integers, floats, strings, and booleans. Practicing simple programs helps build a strong foundation in Python. 🐍💡 Step by step, growing my Python skills! #Python #Programming #DataTypes #List #CodingJourney #Learning #PythonBasics #BeginnerFriendly
To view or add a comment, sign in
-
More from this author
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