PYTHON JOURNEY - Day 34 / 50..!! TOPIC – Python Lists (Basics) Today I explored Lists in Python — a powerful way to store multiple items in a single variable. 1. Creating a List Python fruits = ["Apple", "Banana", "Cherry"] print(fruits) 2. Accessing Items (Indexing) Python starts counting at 0! Python fruits = ["Apple", "Banana", "Cherry"] print(fruits[0]) # Output: Apple print(fruits[-1]) # Output: Cherry (Last item) 3. Adding & Removing Items Python fruits.append("Orange") # Adds to the end fruits.remove("Banana") # Removes specific item print(fruits) Why Use Lists? Keep related data organized They are "mutable" (you can change them after creation) Can hold different data types (Strings, Integers, etc.) Mini Task Write a program that: Creates a list of your 3 favorite movies. Adds one more movie to the list using .append(). Prints the first movie and the total length of the list using len(). #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
Python Lists: Basics and Applications
More Relevant Posts
-
PYTHON JOURNEY - Day 37 / 50..!! TOPIC – Python Dictionaries Today I explored Dictionaries — one of the most powerful and widely used data structures in Python. Unlike lists, dictionaries store data in Key:Value pairs! 1. Creating a Dictionary Think of it like a real-life dictionary: you look up a Word (Key) to find its Meaning (Value). Python student = { "name": "Srikanth", "course": "Python", "day": 37 } print(student["name"]) # Output: Srikanth 2. Adding & Updating Data Dictionaries are mutable, meaning you can change them easily. Python # Adding a new key-value pair student["status"] = "Learning" # Updating an existing value student["day"] = 38 3. Dictionary Methods Useful ways to extract information from your dictionary. Python print(student.keys()) # Gets all keys print(student.values()) # Gets all values print(student.items()) # Gets both in pairs Why Use Dictionaries? Fast Lookups: You don't need to know the index; just the name of the key. Organized Data: Perfect for representing real-world objects (like a user profile or a product's details). Readable: It makes your code look much more intuitive. Mini Task Write a program that: Creates a dictionary for a Smartphone (Brand, Model, and Price). Updates the price of the phone. Adds a new key called "Color". Prints the final dictionary using an f-string. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
To view or add a comment, sign in
-
-
#120 Days Challenge #Day-10 #Python #Dictionary{} in python A dictionary in Python is a collection of key–value pairs. -->Keys are unique and immutable (e.g., strings, numbers, tuples). -->Values can be of any data type and can repeat. hashtag #Methods: 🔸 keys(): Returns all keys as a view object 🔸values(): Returns all values as a view object 🔸items(): Returns key–value pairs as tuples 🔸get(key, default): Safely get a value; returns default if key not found 🔸update(): Adds or updates key–value pairs 🔸pop(key, default): Removes the key and returns its value 🔸popitem(): Removes and returns the last key–value pair 🔸setdefault(key, default): Returns value of key; if absent, adds key with default 🔸clear(): Removes all items 🔸copy(): Returns a shallow copy 🔸fromkeys(keys, value): Creates a new dict with given keys and a default value ✅ In short: Dictionary stores data in key–value pairs and provides methods to access, update, and remove items easily. Pooja Chinthakayala Mam || Saketh Kallepu Sir ||Uppugundla Sairam Sir || Codegnan
To view or add a comment, sign in
-
Python Code Practice: Variables & Data Types Today I practiced the fundamentals that every Python programmer needs to know. Here are the four basic data types I worked with: 🔹 Integer (int) - Whole numbers like age, count, quantity 🔹 Float - Decimal numbers for precision like GPA, prices 🔹 String (str) - Text data enclosed in quotes 🔹 Boolean (bool) - True/False values for logical operations My practice code: python age = 22 cgpa = 3.75 name = "Iqra Munir" is_learning = True print(f"Name: {name}") print(f"Age: {age}") print(f"CGPA: {cgpa}") print(f"Learning Python: {is_learning}") Key takeaway: Understanding data types is more than just theory. It's about knowing which type to use when storing and processing information. Small, focused practice makes these concepts stick. What's one Python fundamental you wish you'd practiced more in the beginning? #Python #DataScience #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Have you ever wondered why Pandas UDFs are used over Python UDFs? PySpark UDFs are written in Python, but Spark itself runs on the JVM. Because of this, Python UDFs run in a separate Python process. Data needs to move from: JVM 👉Python 👉 JVM This causes: 🥹 No proper parallel execution 📊 Extra data movement 📉 Row by row processing 😮💨 As a result, Spark cannot fully use: Catalyst optimizer Tungsten execution engine 💀This leads to slower performance and higher overhead. 🤔 What if row by row processing is done in batches? 🎉 Yes, that's possible This approach is called vectorized execution.Instead of processing one row at a time, data is processed in small batches. This is supported by Pandas UDFs. 😎 Pandas UDFs: Process data in batches Use Apache Arrow for fast data transfer Significantly reduce data movement between JVM and Python 💯 Best Practices 1️⃣ Use Spark built-in functions whenever possible (They are fully optimized and run faster) 2️⃣ Use Pandas UDFs only when Spark functions cannot solve the problem 3️⃣ Avoid Python UDFs as much as possible #spark #sparkoptimization #python #dataengineering
To view or add a comment, sign in
-
-
In this session I learned about the topic is functions of python: *Functions of python: A function is a block of reusable code that performs a specific task.It help make programs modular, readable, and reusable. #Types functions of Python : 1. Built-in Functions: These are predefined functions available in Python. #Examples: print() input() len() type() range() 2. User-Defined Functions: Functions created by the programmer using the def keyword. #Syntax: Python def function_name(): statements #Example: Python def greet(): print("Hello") 3. Functions with Parameters: Functions that accept input values. #Example: Python def add(a, b): print(a + b) 4. Functions with Return Value: Functions that return a result using the return statement. #Example: Copy code Python def square(x): return x * x 5. Lambda Functions: Small anonymous functions written in one line. #Example: Copy code Python square = lambda x: x * x 6.Recursive Function: A recursive function is a function that calls itself to solve a problem by breaking it into smaller sub-problems. #General Syntax: Copy code Python def function_name(): if base_condition: return value else: return function_name(smaller_input). Lakshmi Tejaswi Akula, Ayesha parvin, Athota Amulya,Kadiyam Akanksha, AMULYA DOMA, Lakshmi Tirupatamma , Gunturu Sony, Thanuja Karnati, Konduru sai mounika,Ashok raj Sagana boyana, Rakshandhaa Syed , Chandu Sri Kavya, Polu chandana sri, Jyothika Namburu, Jhansi lakshmi Gopisetti, Veerla Meenakshi, Deevena Florence. Vemuru, vanikumari Buragadda, Sravani Chillara, Sravanthi Katta, Kakumanu Baby Honey , Golla Gayathri , NIKHITHA REPALLE, Nandini Kona,Mikkilineni Bhavana ,Madhavi Posam ,Mudigonda mukhesh,Supriya Nadakuduru,Sharon Samudrala ,Srinivas Yarlagadda, Shaik Afthaf, SHAIK BAJI, Srikar GCV (Trainer)
To view or add a comment, sign in
-
Do you know that everything in Python is an Object? Even the integers and strings. Most beginners are taught that a variable is a "box" where you store data. In Python, that is fundamentally wrong. A variable is just a reference bound to an object. Your variable just points to it. The Anatomy of an Object Every single value in your code, whether it’s the number 5, a string, or a complex function, is a full-blown object. Each object carries three essential things - Identity: A unique memory address - Type: The class that defines its behavior - Value: The actual data stored within it. Why "Everything is an Object" Matters Because everything is an object, Python treats functions, modules, and even classes as first-class values. Functions can have attributes: You can literally attach data to a function, like my_func.metadata = "v1" Classes are objects too: Just as 5 is an instance of int, your class User is actually an instance of a metaclass called type. Uniformity: This design creates a single mental model where attributes and methods operate the same way across all values. The Performance Trade-off Python isn't "slow" by accident; it's a deliberate architectural choice. By making a simple integer a PyObject struct in C (complete with a reference count and type pointer), Python sacrifices raw speed for extreme flexibility and metaprogramming power. The Bottom Line: When you reassign x = 10, you aren't changing the value inside a box. You are moving the label "x" to a completely different object in memory. Understanding this "binding" behavior is the first step toward mastering memory management and avoiding accidental mutations in your code.
To view or add a comment, sign in
-
Day 185/200 Importing files into Python. When importing files in Python, all we need is the file, its location, and the right Python keywords. The required syntax is to start by typing a “with” statement. The keyword “with” handles errors and manages external resources. “with” is often used in file handling to automatically close a file after reading it. After the “with” keyword has been called, to open the file, we use the open() function. open() is a function that opens a file in Python. The first parameter is the name of the file, the second parameter tells Python what action is to be performed on the file. If the file wants to be read, the letter “r” is used in the open() function as the second parameter, if the file wants to be written to, the “r” would be replaced with “w”. Example: with open(“login_attempts.txt”, “r”) as file: “file” in the above code is a variable that contains the file information and must be included in the code as long as we’re in the “with” statement. It basically instructs Python to store the file object in the “file” variable while inside the “with” statement. Lastly, there’s a column, the code that comes after the colon will tell Python what to do with the content of the file.
To view or add a comment, sign in
-
PYTHON JOURNEY - Day 36 / 50..!! TOPIC – Python Tuples Today I explored Tuples — the "reliable cousin" of the list. While they look similar, they have one major difference that makes them special! 1. Creating a Tuple Tuples use parentheses () instead of square brackets. Python coordinates = (10.5, 20.0) colors = ("Red", "Green", "Blue") print(colors) 2. The Golden Rule: Immutability Once a tuple is created, you cannot change, add, or remove its items. This makes them "read-only." Python # This will cause an ERROR: # colors[0] = "Yellow" 3. Packing and Unpacking A cool Python feature where you can assign tuple values to multiple variables at once! Python point = (5, 10) x, y = point # Unpacking print(f"X: {x}, Y: {y}") Why Use Tuples? Safety: Use them for data that should never change (like GPS coordinates or constants). Speed: Tuples are slightly faster than lists in terms of performance. Integrity: Prevents accidental data modification in larger programs. Mini Task Write a program that: Creates a tuple containing the name of a country and its capital city. Try to change the capital city and observe the TypeError. Unpack the tuple into two variables: country and capital, and print them. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
To view or add a comment, sign in
-
-
#PythonProgramming #CodeOptimization #EfficientCoding #OOP #dailylearning In most cases, f-strings are the fastest and most efficient way to format strings in Python. - Let us see the time taken by each method for large number of iterations, time is in seconds -> iterations = 10000000 start = timer() for i in range(iterations): my_string12 = "The variable is %s and pi is approximately %.4f" % (var, var1) end = timer() print("Time taken by % method: ", end - start) start = timer() for i in range(iterations): my_string13 = "The variable is {} and pi is approximately {:.4f}".format(var, var1) end = timer() print("Time taken by format() method: ", end - start) start = timer() for i in range(iterations): my_string14 = f"The variable is {var} and pi is approximately {var1:.4f}" end = timer() print("Time taken by f-strings method: ", end - start) Output -> Time taken by % method: 4.856100000004517 Time taken by format() method: 5.290773199987598 Time taken by f-strings method: 4.271119200013345
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