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.
Syntax-
And refresh the page you will automatically get out from that line.