A small yet confusing mistake made with Python 🐍 You may think you’re creating a tuple here: x = (5) But you’re not ✖️ This is simply an integer. ❓ Why? Because in Python, ⭐ tuple creation involves a comma, not parentheses alone ✔️ The right way to do it: x = (5,) Now it’s a tuple. Even like this works: x = 5, ❓ Simple rule of thumb: Brackets only group items, but the comma makes it a tuple. Tiny point — but crucial! #Python #CodeTutorials #ProgrammingMistakes #CodingForNewbies #DevTips #100DaysOfCode #PythonTips #ProgrammingTips
Python Tuple Creation Mistake
More Relevant Posts
-
Here's a quick Python tuple unpacking challenge from @dontmisstmr — can you get it right without running the code? nums = (10, 20, 30, (40, 50, 60)) x, y, z, nested = nums a, b, c = nested print(f"{z} and {b}") Tuple unpacking is one of those Python features that looks simple but trips people up the moment nesting gets involved. Drop your answer in the comments — and if you got it wrong, what threw you off? #Python #SoftwareDevelopment #CodingChallenge #ProgrammingTips #TechCommunity
To view or add a comment, sign in
-
🚀 Stop doing this in Python: it turns O(n) into O(n²) without you noticing In Python (and many other languages), strings are immutable. That means every time you concatenate a string, a new object is created instead of modifying the existing one. So if you do this repeatedly inside a loop, you’re not really “adding” to the string, you’re rebuilding it from scratch again and again, which becomes increasingly expensive. Reference: https://lnkd.in/gt_gw3bZ #python #coding #pythontips #pythonprogramming
To view or add a comment, sign in
-
-
There is an important python concept hidden here , can you guess what ? class Hai: def show(self,a,b): print('Hai - show()') print(a,b) class Hello(Hai): def show(self,a): print('Hello - show()') print(a) hello = Hello() hello.show(10) hello.show(10,20) #python
To view or add a comment, sign in
-
Rules for declaring python veriables:- 1) Must start with letters (a-z, A-Z) or underscore _ 2)Must not start with numbers (1 to .... ) 3) Variables are case sensitive ( python and Python both are different) 4) We cannot use keywords as variables ( if, def, while ...) Variable declaration is main part of any program. First impression will be starting with it, so while declaring variables need to take care. #python #learn #fast #beginner #automation
To view or add a comment, sign in
-
Python Clarity Series – Episode 22 Topic: == None vs is None 📌 Checking None the wrong way: if x == None: Works… but not recommended. 👉 Correct way: if x is None: 💡 Why? None is a singleton object 👉 is checks identity (correct here) 👉 == checks value 💡 Rule: Use is None, not == None This is considered best practice in Python. Small detail → Strong coding habit #PythonBestPractices #CleanCode #DeveloperThinking #python #clarityseries
To view or add a comment, sign in
-
-
Python Practice: Split & Join Strings I recently solved a basic yet important problem from HackerRank using Python. Problem: Given a string of space-separated words, split the string and join the words using a hyphen (-). Solution: def split_and_join(line): words = line.split(" ") # split string into list result = "-".join(words) # join list with hyphen return result if __name__ == '__main__': line = input() result = split_and_join(line) print(result) Key Concepts: split() → Converts a string into a list join() → Combines list elements into a string Clean function design for reusability if __name__ == '__main__' for proper execution structure Example: Input: this is a string Output: this-is-a-string What I learned: Even simple problems help build strong fundamentals in string manipulation and writing clean, structured Python code. #Python #CodingPractice #HackerRank #Programming #100DaysOfCode #LearningJourney
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
-
-
Most Python beginners don’t use this simple function. len() It looks small. But it’s very powerful. You can use it to find the length of: 👉 Strings 👉 Lists 👉 Tuples 👉 Dictionaries Example: text = "Python" print(len(text)) # Output: 6 numbers = [10, 20, 30] print(len(numbers)) # Output: 3 Instead of manually counting… Let Python do the work. 👉 Did you know about this function before? #Python #BluJayTechnologies #SoftwareTraining #Learning
To view or add a comment, sign in
-
-
✅ Python: 04 🎯 Nested loops Let's share an interesting concept of python. we've this concept called nested loop, here we can use one loop inside of an another loop. We can get some interesting results. Let's take a look- for x in range(2): # outer loop for y in range(3): # inner loop print(f"({x} , {y})") # for co-ordinates 📌Code explanation: The outer loop will be executed 2 times & the inner loop will be executed 3 times, To begin with, the python interpreter will execute the outer loop first then it'll go to the inner loop and execute codes as follows, then it'll print as commanded and then jumps into the outer loop again, this will continue as per the range mentioned in the code. That's how nested loop works. #PythonProgramming #PythonDeveloper #Coding #python #nestedloopinpython #DataScience #pythondeveloper
To view or add a comment, sign in
-
-
Here's a Python dictionary merge challenge from @dontmisstmr — can you get it right without running the code? dict1 = {"name": "Alice", "age": 25} dict2 = {"city": "Noida", "age": 26} merged = dict1 | dict2 print(merged) The | operator was introduced in Python 3.9. When both dicts share a key, which value wins? Drop your answer in the comments! #Python #SoftwareDevelopment #CodingChallenge #ProgrammingTips #TechCommunity
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
🤩👏