Render a complete year as plain text.
How It Works
calendar.calendar(year) formats all twelve months into one multi-column text calendar. It is intended for display, not arithmetic; use date and monthrange for calculations.
Step-by-Step Example
import calendar
year_text = calendar.calendar(2026)
print('January' in year_text)
print('December' in year_text)
Understanding the Example
- The expression 'calendar.calendar(2026)' supplies the value stored as 'year_text'. This value is then used or checked by the later statements.
- The print() call exposes the result so you can compare it with the behavior described above. Check the value and its type when experimenting.
A successful run of this example prints the following output:
True
True
Where This Fits in a Real Program
For event timestamps, distinguish the displayed local clock from the instant that it represents. Store or exchange an unambiguous aware value, then convert it when displaying it to a user. For repeated calendar appointments, use a geographic timezone so daylight-saving rules are not lost.
Practice: Try It Yourself
Use HTMLCalendar for HTML output and TextCalendar for controlled text formatting.
For this exercise, predict the result before running the changed code. Then explain the difference between the original and modified cases using the actual values, not just whether the program completed.
Further Reading
Read the official Python documentation for complete parameters, return types and exceptions.
Common Beginner Mistakes
- Using the text output as a reliable machine-parsed data source.
- Generate a text calendar for another year and save the string as UTF-8.
Key Takeaways
- Render a complete year as plain text.
- calendar.calendar(year) formats all twelve months into one multi-column text calendar.
- Apply the demonstrated operation to the practice input and verify its result before depending on it in a larger program.