Python 3: How to Write a Program to Print Out the Days of the Week
With the help of the list constructor, print out the days of the week.
In this article, write a simple program to print out the days of the week using the list data type.
Requirements: Have a basic understanding of programming in regards to loops, arrays, and data types.
You can download the current version of Python (3.12.2): Here.
(https://www.python.org/downloads/)
You can download the current version of Python (3.12.2) with the link below. (https://www.python.org/downloads/)
The page provides the packages for the operating systems: Windows, Linux, MacOS, etc.
What Is the List Constructor in Python?
The list constructor is the syntax for creating a list. In Python, a list is created with the constructors:
- []
- List().
range() and xrange() can also be used for creating a list, but in regards to integers.
What Is a List?
A list is defined as a dynamic array or sequence.
The characteristics of a list are:
- A list is ordered
- A list is indexable
- A list is mutable.
Steps to Print Out the Days of the Week.
There are seven days within a week. We will assign the days to a list. Next, use the ‘for loop’ to print the days of the week. Then, end the program by printing “end program.”
Python Codes for Days of the Week.
#An array of the days of the week.
#x represents the strings in the list.
Weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
for x in Weekdays:
print(x)
print("End Program")
Try this:
Rewrite the program using the “List()” constructor.
