Writing a #Python module? Want to control which names are exported via "from .. import *"? Define __all__, a list of strings indicating which names will be exported via "import *": x = 100 y = [10, 20, 30] z = {100, 200, 300} __all__ = ['x', 'z']
Control Exported Names with __all__ in Python
More Relevant Posts
-
Stop writing "clunky" Python. 🐍💻 I used to rely heavily on standard for loops for every data transformation. They work, but they can get messy fast. Today, I’m focusing on List Comprehensions to streamline my workflow. The Challenge: Calculate a 10% tax on prices, but only for items over $20. 🔴 The "Old" Way: 5 lines of code, an empty list, and an append function. 🟢 The Optimized Way: 1 clean, readable line. Less boilerplate, more efficiency. Professional-grade Python is all about writing code that is as readable as it is functional. #Python #DataScience #CodingTips #Pythonic #DataAnalytics #ContinuousLearning
To view or add a comment, sign in
-
1.Number Increasing Pattern using Python loops. Code: s = 5 for i in range(1, s+1): for j in range(1, 1+i): print(j, end=" ") print() Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 2.Star Triangle Pattern using Python and nested loops. Python Code: n = 6 for i in range(1, n+1): for j in range(1, i+1): print('*', end=" ") print() Output: * * * * * * * * * * * * * * * * * * * * *
To view or add a comment, sign in
-
"Now let me build this calculator. This is a substantial Python script — I'll create the full workbook with all sheets, formulas, and formatting in one go." Isn't this world we live in kind of crazy now?
To view or add a comment, sign in
-
Want to include a dynamic value in a multi-line #Python string? That would require both an f-string and a triple-quoted string. Good news: Python supports this! x = 10 y = 20 s = f"""{x} + {y} = {x+y} {x} * {y} = {x*y}""" print(s) # shows 10+20 = 30 and also 10*20 = 200
To view or add a comment, sign in
-
-
I wrote a tutorial on "Filtering Financial Data" with Python's filter() and lambda. If you're not familiar with these functions, this will give you a quick introduction on how to use them. "Filtering Financial Data" https://lnkd.in/eXs9PuQq This is part of my "Python for Finance" series https://lnkd.in/exFszkjG #Python #Finance #Data
To view or add a comment, sign in
-
-
10 useful Python one-liners every developer should know Learn Python → https://lnkd.in/d8-NH2BY Python one-liners Swap two variables → a, b = b, a Reverse a string → s[::-1] Check palindrome → s == s[::-1] Get factorial → math.prod(range(1, n+1)) Flatten a list → [i for sub in lst for i in sub] Find even numbers → [x for x in range(10) if x % 2 == 0] Merge two dictionaries → {**d1, **d2} Count items → Counter(lst) Get unique elements → set(lst) Convert list to string → "".join(lst) Small tricks like these make Python code shorter and more readable. #Python #Programming #CodingTips #LearnPython #ProgrammingValley
To view or add a comment, sign in
-
-
Python Logic: Is this Math or Magic?🤔 Day 8 of my Python journey! C++ logic tells me: You can't add words to numbers. Python logic says: Hold my coffee ☕ Check out this snippet: result = True + True + False * True What do you think the print(result) output will be? Drop your guess in the comments! 👇 A) True B) 2 C) 3 D) Error Hint💡: It comes down to how Python stores Booleans as Integers! #Python #LearninginPublic #30DaysOfCode #ProgrammingLogic #Day8
To view or add a comment, sign in
-
-
Here's a Python collections challenge from @dontmisstmr — can you get it right without running the code? from collections import Counter data = [1, 2, 2, 3, 3, 3, 4, 4] top_element = Counter(data).most_common(1) print(top_element) Counter is one of Python's most underrated built-ins. Do you know what format most_common(1) returns? Drop your answer in the comments! #Python #SoftwareDevelopment #CodingChallenge #ProgrammingTips #TechCommunity
To view or add a comment, sign in
-
Python didn’t throw an error… and that’s the problem x = 10 x = "10" Later: print(x + 5) This crashes. Not when the mistake happened… but later, when the variable was actually used. That’s the difference. Python lets you change types freely (dynamic typing), but errors only show up at runtime. In C++, this wouldn’t even compile. You’d catch it immediately. So the real question is: Do you want errors early… or flexibility first and consequences later? Day 3/30 #Python #C++ #LearningInPublic #30DaysOfCode
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
And don't forget to use a module based naming convention, so you don't actually import x, y and z 😵💫