Skip to content

Aiza-D/Python-Lists-and-loops-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Lists and Loops in Python

Basic Lists and Loops Methods in Python Language.

What are Lists?

A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ].

What are Loops?

Looping means repeating something over and over until a particular condition is satisfied.

Type of Loops

There are mainly two types of loops. Let’s discuss them one by one.

1. For Loop

A for loop in Python is used to iterate over a sequence (list, tuple, set, dictionary, and string).

Flowchart:

image

Fig: Flowchart of a for loop

Syntax:

for iterating_var in sequence:

statement(s)

Example:

image

Fig: for loop example

The preceding code executes as follows: The variable i is a placeholder for every item in your iterable object. The loop iterates as many times as the number of elements and prints the elements serially.

2. While Loop

The while loop is used to execute a set of statements as long as a condition is true.

Flowchart:

image

Fig: While loop flowchart

Syntax:

while expression:

statements  

Example:

image

Fig: While loop

The preceding code executes as follows: We assign the value to variable x as 1. Until the value of x is less than 3, the loop continues and prints the numbers.

Ref: https://www.simplilearn.com/tutorials/python-tutorial/python-loops

About

Basic Lists and Loops in Python Language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published