Configuration

Night mode

Multiple Statements

Learn Python Essentials for Data Science Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Python Introduction Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Python, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

Have more questions?

Learning Booleans

Multiple Statements

More than one conditional statement

You can put multiple conditions together in that statement.

Lets consider a situation where we want to go through all the numbers in a list and sum all the values that are between 4 and 7. For example is our list is: lst = [1,5,4,12,18,6] our result would be 5+4+6 = 15

Steps to a solution:

Create sum = 0

Iterate through list of numbers

If the number > 3 and number < 7, add it to the sum

Solution:

lst = [1,5,4,12,18,6]
#Initialize the sum
s = 0
#Iterate through all the numbers in the list
for number in lst:
#if the number meets our condition, add it to the sum
if (number > 3) and (number < 7):
s += number
# Print out the sum after the loop
print(s)

Or Statements

As well, instead of using and, we can use the or statement. Lets say you have a list of words, and you only want to print out the word if it is more than 5 characters long or it contains the letter s.