📘 **Day 11 – File Handling in Python** Today I learned about **File Handling in Python** 📂 👉 File handling allows us to **create, read, write, and update files**. It helps store data permanently instead of keeping it only in memory. 🔹 **Types of Modes:** * `r` → Read file * `w` → Write (overwrites file) * `a` → Append (adds data) * `x` → Create new file 🔹 **Basic Example:** ```python # Writing to a file file = open("example.txt", "w") file.write("Hello, Python!") file.close() # Reading from a file file = open("example.txt", "r") print(file.read()) file.close() ``` 💡 **Best Practice:** Use `with` statement (auto closes file) ```python with open("example.txt", "r") as file: data = file.read() print(data) ``` ✨ **Key Learning:** File handling is important for saving data like logs, user input, and reports. 🚀 Step by step becoming better in Python! #Day11 #Python #CodingJourney #FileHandling #SkillCourse #DataAnalyst
Python File Handling Basics
More Relevant Posts
-
🔤 Strings in Python – Quick Guide Strings are used to store text data in Python. They are simple, powerful, and used everywhere — from data cleaning to report generation. Creating Strings s1 = 'Hello' s2 = "Python" s3 = """Multi-line string""" Access & Slicing text = "Python" text[0] # P text[-1] # n text[0:3] # Pyt Common Operations "Hello" + " World" # Concatenation "Hi " * 3 # Repetition Useful String Methods text = " hello world " text.upper() # HELLO WORLD text.lower() # hello world text.strip() # remove spaces text.replace("world","Python") text.split() String Formatting (Best Practice) name = "Maha" print(f"Hello {name}") Important: Strings are immutable (cannot be changed directly) text = "hello" text = "H" + text[1:] #Python #PythonBasics #DataAnalytics #Programming #LearnPython #Coding #DataScience #PythonForBeginners #100DaysOfCode
To view or add a comment, sign in
-
Day 4 – Python: Files, Data Formats, Functional Tools & Recursion** The series continues with 15 programs covering practical file handling, structured data, functional programming concepts, and an introduction to recursion and decorators. **Focus areas for Day 4:** Working with the filesystem via `os` and `sys`, reading/writing `csv` and `json`, iteration tools like `enumerate` and `zip`, functional constructs `map`, `filter`, `lambda`, plus recursion fundamentals and a first look at decorators. **Day 4 program list:** | Concept | File | | --- | --- | | Filesystem basics | `01_os_basics.py` | | Cross-platform paths | `02_path_join.py` | | File modes: write vs append | `03_write_append_file.py` | | Line-by-line reading | `04_read_lines.py` | | CSV read/write | `05_csv_read_write.py` | | JSON read/write | `06_json_read_write.py` | | `enumerate()` and `zip()` | `07_enumerate_zip.py` | | `map()` and `filter()` | `08_map_filter.py` | | Lambda for sorting | `09_lambda_sort.py` | | Dictionary methods | `10_dict_methods.py` | | List methods | `11_list_methods.py` | | Recursion: factorial | `12_recursion_factorial.py` | | Recursion: Fibonacci | `13_recursion_fibonacci.py` | | Command-line arguments | `14_command_line_args.py` | | Decorator basics | `15_simple_decorator.py` | **How to use:** All scripts use only the Python standard library. Python 3 required. Run individually: `python 06_json_read_write.py` Run the full set: `python Day4Files.py` **Series progression:** Day 1 → Syntax, I/O, basic logic Day 2 → Functions, lists, dicts, file I/O Day 3 → Exceptions, modules, OOP basics Day 4 → File systems, data formats, functional tools, recursion This stage bridges the gap between writing scripts and working with real data. These are the tools you’ll use daily when automating tasks, processing files, or building CLI utilities. #Python #SoftwareEngineering #DataEngineering #Programming #FileIO #ComputerScience #FunctionalProgramming #Recursion #TechEducation #OpenSource #GitHub #PythonProgramming Threads Link:- https://lnkd.in/gVf8wrpY
To view or add a comment, sign in
-
I think dictionaries might be the first Python topic that actually feels like organizing real life. 🐍 Day 08 of my #30DaysOfPython journey was all about dictionaries, and this one felt especially useful because it is basically how Python stores meaningful information. A dictionary is an unordered, mutable key-value data type. You use a key to reach a value — simple, but powerful. Today I explored: 1. Creating dictionaries with dict() built-in function and {} 2. Storing different kinds of values like strings, numbers, lists, tuples, sets, and even another dictionary 3. Checking length with len() 4. Accessing values using key name in [] or get() method 5. Adding and modifying key-value pairs 6. Checking whether a key exists using in operator 7. Removing items with pop(key), popitem() (removes the last item), and del 8. Converting dictionary items with items() which returns a dict_item object that contains key-value pairs as tuples 9. Clearing a dictionary with clear() 10. Copying with copy() and avoids mutation 11. Getting all keys with keys() and values with values(). These will return views - dict_keys() and dict_values() What stood out to me today was how dictionaries make data feel searchable instead of just stored. That key-value structure makes them one of the most practical tools in Python when working with real information. One more day, one more topic, one more step toward thinking in Python instead of just reading Python. When did dictionaries finally stop feeling confusing for you — or are they still one of those topics that need a second look? Github Link - https://lnkd.in/ewzDyNyw #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
🧠 Python Concept: collections.defaultdict Stop checking keys manually 😎 ❌ Without defaultdict data = {} for key in ["a", "b", "a"]: if key not in data: data[key] = [] data[key].append(key) print(data) 👉 Repeated key checking 👉 More code ✅ With defaultdict from collections import defaultdict data = defaultdict(list) for key in ["a", "b", "a"]: data[key].append(key) print(data) 🧒 Simple Explanation 👉 defaultdict gives a default value automatically ➡️ No need to check if key exists ➡️ Python handles it 💡 Why This Matters ✔ Cleaner code ✔ Less boilerplate ✔ Faster development ✔ Very common in real-world code ⚡ Bonus Example from collections import defaultdict count = defaultdict(int) for char in "hello": count[char] += 1 print(count) 🧠 Real-World Use ✨ Counting frequency ✨ Grouping data ✨ Building maps 🐍 Don’t check keys manually 🐍 Let Python handle defaults #Python #AdvancedPython #CleanCode #BackendDevelopment #SoftwareEngineering #Programming #DeveloperLife
To view or add a comment, sign in
-
-
Most Python classes I've seen in DS projects do too much! They load data, clean it, transform it, run the model, and log results... all in one place. It feels efficient until you need to change one thing and have to re-test everything else. That's the cost of ignoring the Single Responsibility Principle. 🐍 In my latest article, I break down what SRP actually means for Python data pipelines: https://lnkd.in/esKz_ARk This is post 1 of 5 in a series on SOLID principles applied to Data Science code. What's the messiest class you've inherited on a DS project? 👇 #Python #DataScience #SoftwareEngineering #SOLID #DataEngineering
To view or add a comment, sign in
-
Python Data Types — One Post Cheat Sheet Understanding data types is fundamental to writing efficient Python code. Here’s a quick overview: 🔢Numeric int → 10 float → 10.5 complex → 2+3j 🔤 String (str) Ordered & immutable Example: "Hello Python" 📋 List Ordered, mutable, allows duplicates Example: [10, 20, 30] 📦 Tuple Ordered, immutable Example: (10, 20, 30) 🔁 Set Unordered, no duplicates Example: {10, 20, 30} 📖 Dictionary Key–value pairs, mutable Example: {"name": "Maha", "age": 25} 🧠 Boolean True / False Used in conditions 🔍 Check Type type(variable) Choosing the right data type improves performance, readability, and data handling. #Python #DataTypes #PythonBasics #Programming #LearnPython #Coding #DataAnalytics #PythonForBeginners
To view or add a comment, sign in
-
-
90% of Data Work = Cleaning. SQL & Python Side‑by‑Side. Cleaning isn’t just prep it’s analysis. Here’s how SQL and Python mirror each other when tackling: Missing values Duplicates Formatting Outliers 👉Full break down here : https://lnkd.in/gUuRJExK #DataScience #SQL #Python #Analytics #BigData #MachineLearning #CareerGrowth
To view or add a comment, sign in
-
If you've never used Python to clean data before, I feel you. But once you try it, you won't go back. With Python you write it once and run it on any dataset. No clicking around, no manual work, just a pipeline that does the job every time. Here's my go-to data cleaning checklist with pandas 👇 1. Read the file 2. Inspect the data 3. Remove duplicates & handle nulls 4. Fix text & standardize 5. Fix data types 6. Validate & export Swipe to see the code for each step ➡️ If you're just starting with Python this is one of the most useful things you can learn. Save this for your next messy dataset.
To view or add a comment, sign in
-
🐍 Python Data Structures — A Complete Reference Guide One of the most common struggles for Python beginners (and even intermediate devs) is knowing WHEN to use which data structure. str? list? tuple? set? dict? They all look similar at first — but choosing the wrong one can slow down your code or make it harder to read. So I put together a clean, one-stop reference PDF covering all 5 core Python data structures: ✅ str — string operations & text manipulation ✅ list — dynamic sequences & in-place mutations ✅ tuple — immutable records & hashable keys ✅ set — unique elements & O(1) membership tests ✅ dict — key-value mapping & fast lookups Each section includes: → Creation syntax → Common operations with examples → Real output results → A full comparison table (ordered, mutable, duplicates, lookup time & more) → Type conversion cheat-sheet Whether you're just starting out or brushing up before an interview — this is the kind of reference you'll want bookmarked. 📎 PDF attached — free to download & share! Drop a ❤️ if this helped you, and follow for more Python resources. #Python #PythonProgramming #DataStructures #LearnPython #CodingTips #Programming #Developer #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
✅ *Python Basics: Part-3* *Control Flow in Python* 🔁🧠 🎯 *What is Control Flow?* Control flow allows your code to make decisions and repeat actions using conditions and loops. 🔹 *1. Conditional Statements (if, elif, else)* Used to execute code based on conditions: ```python age = 18 if age >= 18: print("You are an adult") elif age > 13: print("You are a teenager") else: print("You are a child") ``` 🔹 *2. Loops* ● *For Loop* – Used to iterate over a sequence (list, string, etc.) ```python fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) ``` ● *While Loop* – Repeats as long as a condition is true ```python count = 0 while count < 5: print(count) count += 1 ``` 🔹 *3. Loop Control Statements* - `break`: Exit the loop - `continue`: Skip current iteration - `pass`: Placeholder that does nothing ```python for i in range(5): if i == 3: break print(i) ``` 💬 *Double Tap ❤️ for Part-4!*
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