
Let’s learn the Python programming language together!
.
.
Step 4 involves two parts that are directly related:
- Arrays (lists)
- Loops
.
.
Arrays are basically an extension of step 2 where you learned about data types and variables. An array is simply a collection of multiple values stored in a single variable. This is a simple way to group pieces of data together.
.
.
Example:
animals =
.
.
Now that you have a collection of data grouped together in one variable, often times you will want to perform some operation on all the values found in that collection. This is where the concept of “loops” come in.
.
.
A loop is simply a language construct that allows you to iterate over all the values in a collection (like an array or list) and perform an operation on each value.
.
.
Most languages have several ways of looping over collections and Python is no different. In fact Python has two main types of loops:
- For loops
- While loops
.
.
“For” loops will execute for every value in a range and “while” loops will execute until a certain condition is met. Here are a couple examples:
.
.
For loop: (prints “Hello” 5 times)
for x in range(5): print(“Hello”)
.
.
While loop: (prints “Hello” 5 times)
x = 0
while x < 5: print(“Hello”)
.
.
For many situations both types of loops can be used, but sometimes you may prefer one over the other.
.
.
Now go forth and start adding arrays and loops to your code!
.
.
#Repost #programming #programminglanguage #pythonlanguage #pythoncode #pythonprogramming #learncode #learntocode #learnpython #technology #codinglife #thatcodinglife #tech #pythonprogramminglanguage #development #webdevelopment #buildtheweb #startwritingcode #pythonarray #pythonarrays #pythonlist #pythonlists #pythonloop #pythonloops #pythonforloop #pythonwhileloop #share2steem


shaneelsomduth
