avatarMoments Online

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

934

Abstract

The page provides the packages for the operating systems: Windows, Linux, MacOS, etc.</p><h1 id="99d1">What Is the List Constructor in Python?</h1><p id="47d2">The list constructor is the syntax for creating a list. In Python, a list is created with the constructors:</p><ul><li>[]</li><li>List().</li></ul><p id="45ba">range() and xrange() can also be used for creating a list, but in regards to integers.</p><h1 id="c0d7">What Is a List?</h1><p id="51a1">A list is defined as a dynamic array or sequence.</p><p id="0018">The characteristics of a list are:</p><ol><li>A list is ordered</li><li>A list is indexable</li><li>A list is mutable.</li></ol><h1 id="61e4">Steps to Print Out the Days of the Week.</h1><p id="2168">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.”</p><h1 id="214b">Python Codes for D

Options

ays of the Week.</h1><div id="0e0c"><pre><span class="hljs-comment">#An array of the days of the week.</span> <span class="hljs-comment">#x represents the strings in the list.</span>

Weekdays = [<span class="hljs-string">"Monday"</span>,<span class="hljs-string">"Tuesday"</span>,<span class="hljs-string">"Wednesday"</span>,<span class="hljs-string">"Thursday"</span>,<span class="hljs-string">"Friday"</span>,<span class="hljs-string">"Saturday"</span>,<span class="hljs-string">"Sunday"</span>]
<span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> Weekdays: <span class="hljs-built_in">print</span>(x) <span class="hljs-built_in">print</span>(<span class="hljs-string">"End Program"</span>) </pre></div><h2 id="e027">Try this:</h2><p id="5485">Rewrite the program using the “List()” constructor.</p><p id="8204"><a href="https://momentsonline.medium.com">©MomentsOnline</a></p></article></body>

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.

Photo by Goran Ivos on Unsplash

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:

  1. A list is ordered
  2. A list is indexable
  3. 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.

©MomentsOnline

Python
Technology
Coding
Software Development
Programming Languages
Recommended from ReadMedium