🚀 Python Series – Day 9: Lists & Tuples (Store Multiple Values Easily!) Till now, we were working with single values. But what if you want to store multiple values in one variable? 🤔 👉 That’s where Lists & Tuples come in! 📦 What is a List? A list is a collection of items stored in a single variable. ✔️ Ordered ✔️ Changeable (Mutable) ✔️ Allows duplicates 🔧 Example: fruits = ["apple", "banana", "mango"] print(fruits) 🔁 Accessing Elements print(fruits[0]) # apple print(fruits[1]) # banana ✏️ Modify List fruits[1] = "orange" print(fruits) ➕ Add Elements fruits.append("grapes") 📦 What is a Tuple? A tuple is similar to a list, but: ✔️ Ordered ❌ Not changeable (Immutable) ✔️ Faster than list 🔧 Example: numbers = (1, 2, 3, 4) print(numbers) 🎯 Key Difference 👉 List = Mutable (can change) 👉 Tuple = Immutable (cannot change) 🔥 Pro Tip: Use: List → when data changes frequently Tuple → when data should stay fixed ⚡ Quick Challenge: What will be the output? x = [1, 2, 3] x[0] = 10 print(x) 👇 Comment your answer! 📌 Tomorrow: Strings in Python (Text Handling Basics) Follow me to learn Python step-by-step from basics to advanced 🚀 #Python #DataScience #Coding #Programming #LearnPython #Beginners #Tech #MustaqeemSiddiqui
Python Lists & Tuples for Multiple Values
More Relevant Posts
-
Python has easy ways to make your text, numbers, and dates look clear and professional. Here are 4 tricks you should try: 1. f-Strings :The easiest way to put variables straight into your text. Fast, readable, perfect for quick outputs. name = "Mayar" age = 22 print(f"My name is {name} and I am {age} years old.") 2. Alignment & Width :Keep tables, reports, or lists neat by aligning text and numbers. Left, center, or right—your choice! print("{:<10} | {:^10} | {:>10}".format("Name", "Age", "Score")) print("{:<10} | {:^10} | {:>10}".format("Mayar", 22, 95)) 3. Template Strings :Create reusable text templates and fill in values later. Makes your code cleaner and easier to manage. from string import Template t = Template("Hello $name, your score is $score.") print(t.substitute(name="Mayar", score=95)) 4. Date & Time Formatting :Show dates and times in a clear, readable way. Useful for reports, logs, or messages. from datetime import datetime now = datetime.now() print(f"Date: {now:%d-%m-%Y} Time: {now:%H:%M:%S}") CodeAcademy_om Kulsoom Shoukat Ali Sultan AL-Yahyai #Python #Coding #PythonTips #Developer #LearnPython #TechSkills #CodeBetter #DateTime
To view or add a comment, sign in
-
-
🚀 Python Series – Day 12: List Comprehension (Write Short & Smart Code!) Till now, we used loops to create lists. But what if you can do it in one clean line? 🤔 👉 That’s where List Comprehension comes in! 🧠 What is List Comprehension? List comprehension is a short and powerful way to create lists. 👉 It replaces loops with a single line of code 🔧 Basic Syntax: [expression for item in iterable] ▶️ Example (Using Loop): numbers = [] for i in range(5): numbers.append(i) print(numbers) ⚡ Same Using List Comprehension: numbers = [i for i in range(5)] print(numbers) 👉 Output: [0, 1, 2, 3, 4] 🔥 With Condition: even = [i for i in range(10) if i % 2 == 0] print(even) 👉 Output: [0, 2, 4, 6, 8] 🎯 Why Use List Comprehension? ✔️ Short & clean code ✔️ Faster than loops ✔️ Easy to read (once you practice) 🔥 Pro Tip: Don’t overuse it 😄 👉 Use it when it makes code simple, not confusing ⚡ Quick Challenge: What will be the output? x = [i*i for i in range(4)] print(x) 👇 Comment your answer! 📌 Tomorrow: Lambda Functions (Anonymous Functions in Python) Follow me to learn Python step-by-step from basics to advanced 🚀 #Python #DataScience #Coding #Programming #LearnPython #Beginners #Tech #MustaqeemSiddiqui
To view or add a comment, sign in
-
-
Day 8 of learning Python 🐍 Built a Contact Book from scratch today — Saves 5 contacts to a file — Reads them back — Filters contacts by city — Counts total contacts — Handles bad data without crashing Starts Here: with open("Contacts.txt" ,"w") as file: for Contact in Contacts: file.write(f"{Contact['name']},{Contact['phone']},{Contact['city']}\n") total = 0 with open("Contacts.txt","r") as file: for line in file: parts = line.strip().split(",") name = parts[0] phone = int(parts[1]) city = parts[2] print(f"{name} - {phone} - {city}") total = total + 1 print(f" total no of contacts {total}") print("chennai contacts") with open("Contacts.txt","r") as file: for line in file: parts = line.strip().split(",") name = parts[0] city = parts[2] phone = int(parts[1]) try: if city == "chennai": print(f"{name}-{phone}-{city} ") except ValueError: pass #Python #LearningInPublic #AIEngineering #100DaysOfCode
To view or add a comment, sign in
-
🚀 Python Essentials: Range, For Loop, Enumerate & List Comprehension 💡"Write cleaner, smarter, and more Pythonic code." 🔢 range Definition: Generates a sequence of numbers. Syntax: range(start, stop, step) Example: for i in range(1, 6): print(i) # 1 to 5 🔄 for loop Definition: Iterates over a sequence. Syntax: for variable in sequence: Example: fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) 🏷️ enumerate Definition: Adds a counter to an iterable. Syntax: enumerate(iterable, start=0) Example: for index, fruit in enumerate(fruits, start=1): print(index, fruit) ⚡ List Comprehension Definition: Concise way to build lists. Syntax: [expression for item in iterable if condition] Example: squares = [x**2 for x in range(1, 6)] print(squares) # [1, 4, 9, 16, 25] ✨ These four tools are the backbone of writing efficient loops and data transformations in Python. Master them, and your code will be cleaner, faster, and more elegant. "Python isn’t just about writing code—it’s about writing it beautifully.” 🔖#PythonProgramming #LearningJourney #CodingInPublic #EntriLearning #CodeNewbie #Python #ProgrammingBasics #DataAnalytics #CareerGrowth #LinkedInLearning #LearnWithMe #BeginnerFriendly #AnalyticsInAction #CodeSmart
To view or add a comment, sign in
-
-
🚀 Day 8 – Mastering Lists in Python Today I explored one of the most powerful data structures in Python – Lists. 🔹 What is a List? A list is an ordered, mutable collection that can store multiple values (even different data types). 💡 Example: my_list = [10, "Python", 3.5, True] 🔹 Key Features: ✔ Ordered → maintains insertion order ✔ Mutable → can modify elements ✔ Heterogeneous → different data types allowed ✔ Allows duplicates 🔹 Important Methods: ➤ append() → adds element ➤ remove() → removes element ➤ pop() → removes last element ➤ insert() → adds at specific position 💡 Example: fruits = ["apple", "banana"] fruits.append("mango") 🔹 Real Learning: Lists are the backbone of problem-solving in Python. Most interview questions revolve around list manipulation. 🎯 Small Practice: nums = [1, 2, 3, 4] Output → [1, 4, 9, 16] @Ajay Miryala 10000 Coders #Python #100DaysOfCode #CodingJourney #DataStructures #LearnPython
To view or add a comment, sign in
-
-
🚀 Day 14/60 – Dictionary Comprehension (Level Up Your Python 🚀) Yesterday you learned list comprehension. Today, let’s level up 👇 🧠 What is Dictionary Comprehension? A quick way to create dictionaries in one clean line. ❌ Traditional Way numbers = [1, 2, 3, 4] squares = {} for num in numbers: squares[num] = num * num print(squares) ✅ Dictionary Comprehension Way numbers = [1, 2, 3, 4] squares = {num: num * num for num in numbers} print(squares) 👉 Cleaner. Faster. More Pythonic. 🔍 With Condition numbers = [1, 2, 3, 4, 5, 6] even_squares = {num: num * num for num in numbers if num % 2 == 0} print(even_squares) ⚡ Real Example names = ["adeel", "ali", "ahmed"] name_length = {name: len(name) for name in names} print(name_length) ❌ Common Mistake {num * num for num in numbers} # ❌ This creates a set Correct: {num: num * num for num in numbers} # ✅ Dictionary 🔥 Pro Tip Use dictionary comprehension when: ✅ You want clean transformation of data ❌ Avoid if logic becomes too complex 🔥 Challenge for today 👉 Create numbers from 1 to 5 👉 Create dictionary where: Key = number Value = cube of number Comment “DONE” when finished ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #PythonProgramming #LearnPython #Coding #Programming #Developer #SoftwareEngineering
To view or add a comment, sign in
-
-
I used to think Data Structures were just a hard exam topic. Then StemLink lectures showed me how they actually work in Python — and everything changed. 🐍 Here's what I learned, broken down simply 👇 --- 🔷 The 4 main data structures in Python: 📋 Lists → ordered, mutable, most used mylist = [] mylist.append("item") # add to end mylist.sort() # sort in place 📖 Dictionaries → key-value pairs, O(1) lookup user = {"name": "Abiya", "age": 20} 🔸 Tuples → like lists but NOT mutable coords = (6.9, 79.8) # can't change this 🔹 Sets → unique values only, no duplicates tags = {"python", "dsa", "python"} # stores only once --- 🔷 How data lives inside structures: Everything stored inside these is called an Element. Elements are ordered in groups → accessed using Indexes. mylist[0] # first item mylist[-1] # last item mylist[0:3] # slice from 0 to 2 --- 🔷 How we move through data: Loops + Indexes work together to iterate through elements. for elem in mylist: # loop through every item print(elem) mylist[int] = x # modify by assignment --- 🔷 The big insight: Lists are the most popular data structure in Python. They connect everything — elements, loops, indexes, methods, and assignment — all in one place. Once you understand Lists deeply, the rest makes sense. These fundamentals go directly into the projects I build. Not just theory. Real code. Which Python data structure do you use the most? 👇 #Python #DSA #DataStructures #StemLink #IITColombo #LearnToCode #CS #StudentDeveloper #BuildInPublic #Programming
To view or add a comment, sign in
-
-
Day 9: Python Functions as First-Class Citizens ⚙️ Mastering neat, organized code is critical for Machine Learning pipelines. Today, I did a deep dive into Python Functions, focusing on how to organize code and how Python uses computer memory: Functional Programming: Functions behave like regular data (numbers or strings). I practiced storing them in variables, giving them as inputs to other functions, and having functions create new functions. This makes processing data in steps much easier. Decomposition & Abstraction: Moving past one giant block of code to build separate "boxes" for specific tasks (like separate sections for loading data, cleaning it, and training the AI model). I focused on writing clear instructions (docstrings) inside each one. Scoping & Frame Stack: Learned exactly how Python keeps track of where variables "live." A variable created inside a function is kept separate from variables outside, preventing accidental mistakes and data mix-ups. ⚡ Arbitrary Arguments (*args): Used *args to create super flexible functions that can accept any amount of inputs. This is crucial when you don't know exactly how much data you will get, ensuring the script doesn't crash. Moving from code that "works" to code that is neat, well-documented, and ready for production. 📈 #Python #LearningInPublic #ArtificialIntelligence #SoftwareEngineering #DataPipelines #Modularity #100DaysOfCode
To view or add a comment, sign in
-
-
Day 2 of Learning Python Most people don’t fail in Python… They fail because they ignore the basics. Here are 4 things you MUST know 👇 1. Data Types Everything in Python has a type: int, float, str, bool 🎥 👉 https://lnkd.in/gDNAyz6E 2. Data Structures Store multiple values efficiently: ✔ List → ordered, changeable ✔ Tuple → ordered, fixed ✔ Set → unique values ✔ Dictionary → key-value pairs 🎥 👉 https://lnkd.in/gqWWihBJ 3. Indexing & Slicing Access data like a pro: list[0] → first element list[-1] → last element list[0:3] → slice 🎥 👉 https://lnkd.in/g7QVQFzK 4. Operators Perform actions: ➕ Addition ➖ Subtraction ✖ Multiplication ➗ Division 🤔 Logical , Comparison 🎥 👉https://lnkd.in/g_7gZcUZ 💡 Reality Check: You can’t become a Data Scientist just by watching tutorials… Just like you can’t become a cricketer 🏏 by watching IPL. 👉 You need practice. #Python #Coding #DataScience #MachineLearning #LearnToCode
To view or add a comment, sign in
-
-
I recently explored Python Lists and how they work in real-world scenarios, and here’s what I learned 👇 Python lists are one of the most powerful and beginner-friendly data structures. They allow us to store multiple values in a single variable and work with them efficiently. In my blog, I covered: • Creating and accessing lists • Indexing and slicing • Adding, removing, and updating elements • Important methods like append(), remove(), sort(), reverse() • Real-world examples like shopping lists, student marks, and to-do lists 🔑 Key Learnings: • Lists are mutable, which makes them flexible for real-time changes • Built-in methods simplify complex operations • Lists are widely used in real-world applications and problem-solving Read the full blog here: https://lnkd.in/g5kK2jPF #Python #DataStructures #Coding #Programming #LearningInPublic #Tech #Beginners A heartfelt thanks to Vishwanath Nyathani, Raghu Ram Aduri, Kanav Bansal, and Mayank Ghai, along with my mentors Harsha Mg for their continuous guidance and motivation.
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
You realize that these can all be one liners in perl???