Python for beginners
Rasheedat Olufunke Yusuf
Graphic designer || Administrator || English Coach || caregiver || Hairstylist
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.
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.
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:
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:
领英推荐
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:
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"]
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
Thanks for reading!
Please feel free to use the comment section
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?