How to Use Conditionals and Loops in Python
Originally published: 27/11/2018 11:52
Publication number: ELQ-15715-1
View all versions & Certificate
certified

How to Use Conditionals and Loops in Python

Let’s see how to combine conditionals and loops in Python.

  • Step n°1 |

    Conditional

    To print all the values from 2 to the power of 0, 2 to the power of 1, and so on, until 2 to the power of 9, we can use the following code: for “n” in range of 10, print “2 double star n”. I will also have to insert a comma, because I would like to see the output on a single line.


    I guess you can agree it was not necessary to specify the name of a list that exists in our code – using a list created through the “range” function is going to work too!

    How to Use Conditionals and Loops in Python image
add_shopping_cartContinue reading for free (70% left)

Reviews

  • Be the first to review this How-To Method

    Write a review


keyboard_arrow_leftkeyboard_arrow_right

More Best Practices from 365 Data Science

See all
keyboard_arrow_leftkeyboard_arrow_right

Discussion feed for How To Use Conditionals And Loops In Python

The user community and author are here to help. Go ahead!


0.0 / 5 (0 votes)

please wait...