Keyword-only parameters in a #Python function can have a default: def myfunc(*, a, b=10): return f'{a=}, {b=}' Now call it: myfunc(a=5) # use the default myfunc(a=5, b=6) # override the default Remember: parameters with defaults come *after* those without.
Python function parameter defaults
More Relevant Posts
-
Want to parse a #Python string into a datetime? Use strptime, passing (a) the string and (b) the date format spec: datetime.datetime.strptime('2026-04-01', '%Y-%m-%d') datetime.datetime.strptime('26-April-01', '%y-%B-%d') Both return datetime.datetime(2026, 4, 1, 0, 0)
To view or add a comment, sign in
-
-
If a #Python string contains an ISO-formatted date, skip strptime and use datetime.fromisoformat: import datetime as dt dt.datetime.fromisoformat('2026-04-12') # returns datetime at midnight dt.datetime.fromisoformat('2026-04-12 12:34:56') # returns datetime at 12:34:56
To view or add a comment, sign in
-
-
⚡ Python Tip: list.append(x) vs list.extend(x) 👉 append(): Adds one element [1,2].append([3,4]) → [1,2,[3,4]] 👉 extend(): Adds elements individually [1,2].extend([3,4]) → [1,2,3,4] 📌 Small difference. Big impact. #Python #CodingTips #LearnPython
To view or add a comment, sign in
-
Having a tough time remembering #Python strptime vs. strftime? - The "p" (strptime) is for parsing, getting a datetime from a string - The "f" (strftime) is for formatting, getting a string from a datetime For help remembering the format codes, turn to https://buff.ly/oEdYGMI !
To view or add a comment, sign in
-
-
Here’s a tiny Python change that pays off fast. Python tip: use `@dataclass(slots=True)` for high-volume models. It removes per-instance `__dict__`, which usually means lower memory usage and slightly faster attribute access. Great for DTOs, parser outputs, event payloads, and cache objects where shape is fixed. Mini rule: if the object schema is stable, add `slots=True` by default. #Python #Performance #CodeQuality #SoftwareEngineering
To view or add a comment, sign in
-
-
Tiny Python upgrade for cleaner analytics code: Use Counter instead of manual dict increments. You get frequency maps in one pass and top-N insights with most_common(). Less boilerplate, fewer mistakes, faster review. Mini pattern: - counts = Counter(values) - top = counts.most_common(3) - act on thresholds #Python #CodingTips #Backend #DevTips #SoftwareEngineering
To view or add a comment, sign in
-
-
Learn how to build a recommendation system with Python and TensorFlow, including benefits, challenges, and applications https://lnkd.in/g56_xGKm #RecommendationSystem Read the full article https://lnkd.in/g56_xGKm
To view or add a comment, sign in
-
-
Want to take a #Python #Pandas series of strings, and get datetime values? Use pd.to_datetime: pd.to_datetime(df['x']) Notice: It's not a method! It's a top-level pd function. Specify a non-standard "format" with a strftime string: pd.to_datetime(df['x'], format='%d/%m/%Y')
To view or add a comment, sign in
-
More from this author
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