Loops in Python | With Jupyter Notebook -Technical Teacher

Loops in python
Loops in python

Loops in Python | Using Jupyter Notebook (Python for Data Science)

A loop plays an important role in programming language. A loop means in simple language, a process keep on running when the condition is true and stops when the condition failed.

We will discuss here about python loops by using jupyter notebook.

Before we start you should know important points regarding python programming language-

  • Python is an object-oriented programming language. In python, there are no curly braces, normal braces only colon is used.
  • Indention is most important part of syntax of python language.

Python Indentation

In Python, white-spaces are most important. White-spaces at the beginning of lines are called Python Indentation.

If you are not using proper indention in python then it gives, following error that is-

IndentationError: unexpected indent

 Now, I start with while loop in python by using jupyter notebook.

 The “While” loop-

These loops are executed whether condition is True or False.

When you don’t know how much time iteration need to be run than you use while according to condition it will run but in FOR loop you exactly know the iteration (Ex. you want to print table of 2 than you have to run it 10 times)

When I am running while loop for false condition you will get no output.

Syntax-

while False:

print("yourstechnicalteacher")

 

When I am running while loop for true condition you will get same output again and again. Your cell becomes busy and your browser will be in hang state.

Syntax-

while True:

print("yourstechnicalteacher")

 

How would you stop a busy cell in jupyter(ipython)?

It’s better to restart kernel.

In toolbar click on Kernel then click on Restart.

Shortcut –click two times zero (00).

And refresh the page you will automatically get out from that line.

Stop Kernel

How would you stop a busy cell in jupyter(ipython)?

 
 
Syntax-
 
t=1

while t<10:

    print(t)

    t=t+2
 
 
 
 

The “For” loop-

 I am using range function for iteration.

Syntax-

for i in range(4):

print("yourtechteacher")

Output-

 
 
 
Now, I am using for loop for printing letter in different line.
 

Syntax-

for i in 'jupyter':

print('letter:',i)

Output-

letter: j

letter: u

letter: p

letter: y

letter: t

letter: e

letter: r

I hope you will understand loops in ipython using jupyter notebook. I meet you in next article.

Thank you!!

Leave a Reply

Your email address will not be published. Required fields are marked *