Day 17/120 of my Python Full Stack Journey Topic: Loop Control Statements – break, continue, pass Today I learned how to control the flow of loops using special keywords. #Python #BreakContinuePass #ProgrammingBasics #DailyLearning #FullStackDeveloperJourney #KeepGoing Pooja Chinthakayala mam Saketh Kallepu sir Uppugundla Sairam sir Codegnan #break #break statement is used to terminate the entire loop a=10 while a>1: print(a) a=a-1 a=10 while a>1: a=a-1 print(a) a=10 while a>1: print(a) a=a-1 if a==4: break for i in range(10): print(i) for i in range(10): if i==8: break print(i) a="python" for i in a: if i=="h": break print(i) #continue #the continue statement is used to skip the current iteration and rest of the code will continue a=20 while a>2: print(a) a=a-1 a=20 while a>2: a=a-1 print(a) a=20 while a>2: print(a) a=a-1 if a==12: continue a=20 while a>2: a=a-1 if a==12: continue print(a) for i in range(15): if i==9: continue print(i) a="code" for i in a: if i=="o": continue print(i) #pass #pass statement is a null statement it does nothing but syntactically we need. a=30 while a>5: print(a) a=a-1 if a==15: pass for i in range(14): if i==10: pass print(i)
Learning Loop Control Statements in Python
More Relevant Posts
-
🗓️ Python Daily – Day #1 🎯 Topic: Mastering List Comprehensions 🚀 💡 Concept/Quiz/Challenge: Transform this simple for-loop into a single line of code using a **list comprehension**: ```python numbers = [1, 2, 3, 4, 5] squares = [] for n in numbers: squares.append(n**2) print(squares) ``` Rewrite it so that `squares` is created in one line. ✅ Hint: Think about enclosing an expression in square brackets and using a `for` clause inside. 🧩 Answer/Explanation: ```python squares = [n**2 for n in numbers] print(squares) ``` List comprehensions are a compact, readable way to generate lists based on existing iterables. They are not only shorter but often faster than traditional loops! Try adapting this to create lists of cubes, or even filtering lists!
To view or add a comment, sign in
-
Over the weekend, I delved into Python's functions, uncovering some valuable insights: - Functions streamline your code by allowing you to write a block once and reuse it, ultimately saving time and simplifying maintenance efforts. - Apart from lambda functions which deviate from the standard syntax, All functions typically start with "def ***(a, b): " where *** denotes the function's name, with relevant variables within the parentheses like (a, b) in the example. - The function's body dictates the iteration process over the variables, resulting in a specific output through the "return" statement. Functions serve as a cornerstone for automation. - Demonstrated below is a 'fizzBuzz' function, designed to list numbers from 1 to a specified number "n". Notably, multiples of 3 are replaced by "Fizz", multiples of 5 are replaced by "Buzz", and multiples of 15 are replaced by "FizzBuzz". Fizzbuzz(5) Upon calling the function with "n" assigned as 5 (per the line of code above), the result is returned as: ['1', '2', 'Fizz', '4', 'Buzz'] #Python #Functions
To view or add a comment, sign in
-
-
🖼️ Day 38 | Python GUI Project — Open & Display Images in Tkinter Using Pillow #100DaysLearningChallenge Today, I learned how to open and display images in a Python GUI using Tkinter and Pillow (PIL) — a very handy combo for any GUI project! 💻 🧠 Simple Explanation Here’s what this project does — step by step 👇 🎯 The Goal: To show an image inside a Python Tkinter window (just like a mini photo viewer app). ⚙️ How It Works: 🪄 Step 1: Open the Image (Pillow) pil_image = Image.open('./MySirG.jpg') This opens the image file from your computer using the Pillow library. 🎨 Step 2: Convert for Tkinter Display tk_image = ImageTk.PhotoImage(pil_image) Tkinter can’t display normal images directly, so we convert it into a Tkinter-friendly format using ImageTk.PhotoImage. 🖼️ Step 3: Display It on Screen l1 = tk.Label(root, image=tk_image) l1.pack() We place the image inside a Label widget and display it in the window using .pack(). ✨ Bonus: Resize the Image pil_image = pil_image.resize((200, 200)) Resize your image (200×200 pixels) so it fits neatly inside your window. 💡 Key Takeaway: Pillow (PIL) → Opens & edits images ImageTk → Converts for Tkinter Label → Displays image in GUI That’s it! You’ve just built a simple image viewer GUI app in Python. 📷 💻 Code Link: https://lnkd.in/dXkzUGY8 🙏 Special thanks to Saurabh Shukla Sir for making GUI programming with Tkinter so enjoyable and easy to understand! #100DaysLearningChallenge #Python #Tkinter #Pillow #PythonProjects #Learning #Day38 #CodingJourney #MySirG #BeginnerFriendly #GUIProgramming
To view or add a comment, sign in
-
-
🚨 Stop killing your Python performance with string concatenation! I see this mistake everywhere: ❌ The slow way (O(n²)) result = "" for word in words: result += word # Creates a NEW string every time! Here's what's actually happening: Every += creates an entirely new string in memory, copying all previous characters. Process 1000 strings? That's ~500,000 character copies. Ouch. The fix is beautifully simple: # ✅ The fast way (O(n)) result = [] for word in words: result.append(word) # Just adds to list return ''.join(result) # Single concatenation at the end Why it matters: → Strings are immutable in Python → Lists are mutable and efficient for building → One final join operation vs thousands of copies → Can be 100x+ faster on large datasets Real impact: I've seen this single change cut processing time from minutes to seconds in production code. Pro tip: For simple cases, list comprehensions + join are even cleaner: result = ''.join([word for word in words]) What's your favorite Python performance trick? #Python #Programming #SoftwareEngineering #CodingTips #PerformanceOptimization #CleanCode #TechTips #PythonProgramming #SoftwareDevelopment #CodeEfficiency
To view or add a comment, sign in
-
Had one of those classic "bug" moments that turned out to be a fundamental Python feature: lexical closures. It was bugging me, so I had to go deep. In short, a closure is when a nested function remembers the variables from its "enclosing" scope, even after that scope has finished. Why it's powerful: It's perfect when you need multiple functions to react to a single, changing piece of state without using global variables. Why it's a headache (the 'gotcha'): It can be a real trip-up if you're not expecting it, especially in loops where all your functions might end up using the last value of the loop variable. (Ask me how I know 😂) It's a classic feature that, when used right, is super clean. When used by accident, it's a real head-scratcher. What's a "simple" Python feature that's given you a headache before? #Python #SoftwareDevelopment #Programming #PythonDeveloper #DevCommunity
To view or add a comment, sign in
-
-
Python Tip – Day 6: Make Your Loops Cleaner with enumerate() Ever used range(len()) to get both index and value in a loop? There’s a better and more Pythonic way , use enumerate()! Here’s a quick example: x = [1, 2, 3, 4, 5, 6] s = 0 for i in enumerate(x): print(i[0], i[1]) enumerate() returns both the index and value as a tuple! That’s why i[0] gives the index and i[1] gives the list element. Try unpacking it directly for cleaner code: for index, value in enumerate(x): print(index, value) enumerate() improves readability and makes your code look more professional. Keep your loops clean and efficient! #Python #30DaysOfpythonCode #PythonTips #CodingJourney #LearnPython #CodeBetter
To view or add a comment, sign in
-
-
🗓️ Python Daily – Day #1 🎯 Topic: List Comprehensions Made Easy! 💡 💡 Concept/Quiz/Challenge: Can you transform this loop into a neat one-liner using list comprehension? ```python numbers = [1, 2, 3, 4, 5] squares = [] for n in numbers: squares.append(n ** 2) print(squares) ``` Rewrite the above code using a single line of Python with list comprehension. ✅ Hint: Think of creating a new list by applying an expression to each item in the original list. 🧩 Answer/Explanation: ```python numbers = [1, 2, 3, 4, 5] squares = [n ** 2 for n in numbers] print(squares) ``` List comprehensions combine loops and list creation in one elegant line, improving readability and often performance. Try experimenting by adding conditions or modifying the expression!
To view or add a comment, sign in
-
Practicing Python by building 3 small projects I’ve been focusing on core Python concepts by shipping tiny command-line apps. Nothing fancy, just real reps. 1) Number Guessing Game Computer picks a number 1–100 → you guess. Feedback after each try: Too high / Too low / Correct. Concepts: input handling, random, loops, guardrails. 2) Rock–Paper–Scissors Play vs the computer; r/p/s inputs, q to quit. Keeps track of wins/losses/ties with clear prompts. Concepts: branching, simple state, replay loop. 3) Python Trivia Quiz 5 random questions from a small in-memory set. Case-insensitive answers, instant feedback, final score /5. Concepts: dicts, random sampling, string ops. I’ll post the GitHub link in the comments. If you have ideas for the next small project. I’m all ears. #Python #LearningInPublic #DevOps #Automation #BeginnerProjects #BuildNotWatch
To view or add a comment, sign in
-
Python Functions — Definition, Types, and 4 Classic Problems 🔥 🐍 Function Syntax & Definition A function in Python is a block of code that performs a specific task and can be reused multiple times. It helps to make the code organized, readable, and modular. 🧠 Syntax: def function_name(parameters): # block of code return value 🚀 Advantages of Functions ✅ Avoids repetition of code 📖 Improves readability and organization 🧱 Enables modular programming 🪄 Easier debugging and maintenance ♻️ Promotes code reusability 🧮 Types of Functions 1️⃣ Without arguments and without return value 2️⃣ With arguments and without return value 3️⃣ Without arguments and with return value 4️⃣ With arguments and with return value 💻 Function Practice Problems 1️⃣ Sum of Digits – Find the sum of all digits in a number using loops. 2️⃣ Reverse of a Number – Reverse digits using mathematical logic. 3️⃣ Armstrong Number – Check if the number equals the sum of its digits raised to their count. 4️⃣ Perfect Number – Check if the number equals the sum of its proper divisors. LogicWhile #Python #Functions #PythonCoding #LearnPython #PythonWithBalaji #CodingPractice #CodeNewbie #100DaysOfCode #PythonForBeginners #DeveloperCommunity #ProblemSolving #TechLearning #CodeWithMe #PythonDevelopers #StudyWithBalaji #DailyPython
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