Python for beginners

Python for beginners

Last week, I shared some of what I have learnt so far on the Python for beginner course that I started some weeks back on Simplilearn , I wrote about variables and the 4 built-in data types we have in python which are: List, Tuple, Set and Dictionary.

Today, I will continue with loops and the types of loops we have in python, Array and Function.

  1. Loops

Loops are instructions that repeats multiple times as long as some condition is met. ?If the condition of a loop is true, the statement in the loop are executed and once again the condition is checked. This loop continue as long as the the condition is satisfied. Once the condition fail the program control exit out of the loop and all the statement following it are executed.

Python programming language provides the following types of loops to handle looping requirements. While all the ways provide similar basic functionality, they differ in their syntax and condition checking time.

No alt text provided for this image

Types of loop

A. While loop

The while loop is used to repeat a section of code several times until a specific condition is met. And when the condition becomes false, the line immediately after the loop in the program is executed.

Example:

No alt text provided for this image

B.?????For loop

For loop is used to iterate over a sequence, which could be a list, tuple, array or a string. This is less like the?for?keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. With the?for?loop we can execute a set of statements, once for each item in a list, tuple, set etc.

Example:

No alt text provided for this image

C. Nested loop

Nested loop could be a for loop in a for loop, while in while, for in while or while in for.

Example:

No alt text provided for this image


2. Array

Array is a container that holds multiple values of the same type. To simplify, we can think of an array a fleet of stairs where on each step is placed a value (let’s say balls with different color). Here, you can identify the location of any of ball by simply knowing the count of the step they are on. Array is used in Python by a module named?array. It can be useful when we have to manipulate only a specific data type value.?Python does not have built-in support for Array, but python list can be used instead.

Example: cars = ["Ford",?"Volvo",?"BMW"]

No alt text provided for this image

3. Function

A function is a set of organized and reusable block code that performs single, related action. It only runs when it is being called. A function is defined using the “def” keyword in python

No alt text provided for this image

Thanks for reading!

Please feel free to use the comment section

Azeez Olanrewaju Shoderu

Coach @A.O.S Abroad ?? AI Consultant ???? Publisher ?? Amazon Best-Selling Author ?? Simplifying AI, Empowering Professionals to Succeed in Life, Build Profitable Careers or Businesses Worldwide.

2 年

A huge well done to you! I am enjoying these series, please keep it up. Though, I have a question, why is the % sign and letter d added to the print statement in the last example?

要查看或添加评论,请登录

Rasheedat Olufunke Yusuf的更多文章

  • 5 Top libraries in python

    5 Top libraries in python

    We have different libraries in python but I would be abstracting the 5 top libraries in this article. In the last few…

  • Object-oriented Programming (OOPs)

    Object-oriented Programming (OOPs)

    Have you heard about Learning by Teaching? To me it is learning something and then present it to others. This method…

    3 条评论
  • Sleep Paralysis: All you need to know

    Sleep Paralysis: All you need to know

    Have you ever tried to fall asleep or even wake up and you suddenly feel a pressure on your chest or sense a presence…

    5 条评论
  • A Letter of Self-Reflection

    A Letter of Self-Reflection

    How should I put it? The 19th of July 2022 was just a normal day as every other day and I have been thinking about my…

    2 条评论

社区洞察

其他会员也浏览了