Copying vs Reference 🐍 I thought this would create a copy: b = a It didn’t. a = [1, 2, 3] b = a b.append(4) print(a) 👉 [1, 2, 3, 4] Both variables point to the same list. No copy was made. In Python, variables are just labels, not containers. When you use =, you aren’t duplicating data, you’re just giving the same memory address a second name. To actually copy: b = a.copy() Looks the same. Behaves completely differently. 💡 And also: .copy() only goes one layer deep and that's why we need deep copy. ➡️ Assignment ≠ Copy Day 17/30 #Python #30DaysOfCode #SoftwareEngineering
Chhavi Mendiratta’s Post
More Relevant Posts
-
Most implementations of the State pattern in Python look very “clean”. Lots of small classes. A base interface. One class per state. But if you’ve ever worked with one in a real project, you know the downside: transitions are scattered, behaviour is hard to see in one place, and adding new states often means touching multiple files. In today’s video, I rebuild the State pattern in a very different way. Instead of relying on inheritance, I make the state machine explicit as data and use decorators to define transitions. The result is a small, reusable engine where the entire flow becomes visible at a glance. If you’re interested in writing Python that’s easier to reason about and extend, this is a pattern worth understanding. 👉 Watch here: https://lnkd.in/eg22yEHR. #python #softwaredesign #designpatterns #statemachine #cleancode
To view or add a comment, sign in
-
-
Finally moved Python & AI project from local to live! 🎈 I’ve been experimenting with Python lately and finished building a simple Personal Assistant for my morning routines and productivity. It was fun to step outside .NET and try out some new tools: ⚡ Groq : Really impressed with how fast the responses are. 🐍 Python: Getting more comfortable with the syntax every day. 🖥️ Streamlit: Made it super easy to put a clean UI on top. It’s work in progress, but you can check out V1 here: https://lnkd.in/gwyuaGZt #Python #Streamlit #PersonalProject #BuildingInPublic #WomenInCode
To view or add a comment, sign in
-
-
🅸🅽🅿🆄🆃 & 🅾🆄🆃🅿🆄🆃 🅵🆄🅽🅲🆄🆃🅸🅾🅽🆂 📦 Definition: In Python, Input is how we get data from the user into our program, and Output is how the program displays information back to the user. 🏠 Real-World Example: Think of a Vending Machine. Input: You press the buttons to tell the machine you want a "B3" (snack code). Output: The machine displays "Price: $1.50" on the screen and then drops your chips! 🍟 Without that type interaction, the machine is just a silent box of snacks. Here is how we do it in Python: 👉 input(): This function pauses the program and waits for you to type something. Python always treats input as a string by default, so if we want numbers, we will need to wrap it in an int() or float(). 👉 print(): It takes whatever is inside the parentheses and splashes it onto the screen for the world to see. #python #inputoutput #codingtips #pythonsimplified #datananalytics #learnpython
To view or add a comment, sign in
-
-
Most implementations of the State pattern in Python look very “clean”. Lots of small classes. A base interface. One class per state. But if you’ve ever worked with one in a real project, you know the downside: transitions are scattered, behaviour is hard to see in one place, and adding new states often means touching multiple files. In today’s video, I rebuild the State pattern in a very different way. Instead of relying on inheritance, I make the state machine explicit as data and use decorators to define transitions. The result is a small, reusable engine where the entire flow becomes visible at a glance. If you’re interested in writing Python that’s easier to reason about and extend, this is a pattern worth understanding. 👉 Watch here: https://lnkd.in/e9Y3xGNF. #python #softwaredesign #designpatterns #statemachine #cleancode
To view or add a comment, sign in
-
-
Python Series — Day 3 🧠 Let’s level it up a bit 👇 What will be the output of this code? def modify_list(lst): lst.append(4) a = [1, 2, 3] modify_list(a) print(a) Options: A. [1, 2, 3] B. [1, 2, 3, 4] C. Error D. None Think carefully 👀 (Hint: It’s not about functions… it’s about how Python handles data) Drop your answer 👇 Answer tomorrow 🚀 #Python #CodingChallenge #LearningInPublic #DataEngineering #Tech
To view or add a comment, sign in
-
-
Pyramids in Python print('\nNormalPyramid')for i in range(5): x='*' x=x*i print(f'{x:^10}')print('\nInvertPyramid\n')for i in range(5): x='*' x=x*(5-i) print(f'{x:^10}')print('Left sided Pyramid')rows = 5for i in range(1, rows + 1): stars = '*' * i print(f'{stars:<10}')print('\nRightsidedPyramid') rows = 5for i in range(1, rows + 1): spaces = ' ' * (rows - i) stars = '*' * i print(f'{spaces}{stars}')#pythoncode
To view or add a comment, sign in
-
-
Day 43/100 – #100DaysOfCode 🚀 Solved LeetCode #2610 – Convert an Array Into a 2D Array With Conditions (Python). Today I practiced hashmap (frequency counting) to construct a 2D array based on given conditions. Approach: 1) Create a frequency map to count occurrences of each element. 2) Initialize an empty result list. 3) While the frequency map is not empty: 4) Create a new row. 5) Iterate through keys and add each number once to the row. 6) Decrease its frequency and remove it if it becomes zero. 7) Add the row to the result. 8) Return the final 2D array. Time Complexity: O(n) Space Complexity: O(n) Learning how frequency maps help in structuring data efficiently 💪 #LeetCode #Python #DSA #HashMap #Arrays #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Ever tried to sort a list and ended up with None? The logic looks correct: nums = [3, 1, 2] sorted_nums = nums.sort() print(sorted_nums) 👉 Output: None Why did it fail? In Python, there is a big difference between a Method that modifies an object and a Function that returns a new one. 1️⃣ .sort() is a Method: It modifies the original list "in-place." It doesn't need to return anything because the work is done directly on the original variable. 2️⃣ sorted() is a Function: It creates a brand-new list and leaves the original one exactly as it was. Use .sort() when you want to save memory and don't need the original order anymore. Use sorted() when you need to keep your original data safe and want a new sorted version. #Python #30DaysOfCode #BCA #LearningInPublic #Day22 #JECRC
To view or add a comment, sign in
-
-
Python Challenge – Can you solve this? Today was all about deep-diving into Lists vs. Sets and I came across a common mistake that we can sometimes overlook. Let’s test your Python understanding👇 numbers = [1, 2, 3] numbers.append([4, 5]) print(len(numbers)) A) 3 B) 4 C) 5 D) Error It’s a classic interview question that tests if you truly understand how Python handles memory and lists. Day 15/30 #30DaysOfCode #DataStructures #Day15 #PythonQuiz
To view or add a comment, sign in
-
-
A manager once told me her team spent 3 hours every Monday compiling a report that nobody read until Wednesday. 3 hours. Every single week. Just moving numbers from one spreadsheet to another. That's 150+ hours a year on a task that a Python script can do in 30 seconds. The problem wasn't the people. The problem was the process. If your team has a Monday morning task like this — let's talk. 📩 DM me. #ProcessAutomation #Python #OperixSolutions
To view or add a comment, sign in
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
If you thought a = b creates a copy, you probably learned C++ before Python 😏