# Lesson 2: List, Boolean and Condition

This lesson learns are based on Python book page 26-30

# Tools

https://trinket.io/ (opens new window)

# Lesson Learns

# What is the list?

When you want to store a lot of data, or perhaps the order of the data is important, you may need to use a list. A list can hold many items together and keep them in order. Python gives each item a number that shows its position in the list. You can change the items in the list at any time.

# Not a good example

my_friend_0 = "James"
my_friend_1 = "David"
my_friend_2 = "Anthony"
my_friend_3 = "Larry"
1
2
3
4

# Using List

friends = ["James", "David", "Anthony", "Larry"]
1

# Getting a item from a list

friends = ["James", "David", "Anthony", "Larry"]
print(len(friends)) # 4
print(friends[0])   # James
print(friends[1])   # David
print(friends[2])   # Anthony
print(friends[3])   # Larry
1
2
3
4
5
6
output
4
James
David
Anthony
Larry
1
2
3
4
5

# Boolean, Logic and Condition

# Boolean

There are only True or False values for a boolean value.

bool1 = True
print(bool1)
bool2 = False
print(bool2)
1
2
3
4
output
True
False
1
2

# Logical operators

Symbol Meaning
== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

# Pink and Blue bees

bee

pink_bees = 2
blue_bees = 4

answer1 = pink_bees > 5
answer2 = blue_bees < pink_bees 
answer3 = blue_bees >= 1
answer4 = pink_bees > 20

print(answer1)
print(answer2)
print(answer3)
print(answer4)
1
2
3
4
5
6
7
8
9
10
11
12
output
False
False
True
False
1
2
3
4

# Condition

WARNING

Please be careful about Indent

if ...
	print()
^^^^ 1 tab
1
2
3
pink_bees = 2
blue_bees = 4
if(pink_bees < blue_bees):
	print("There are Pink Bees less than Blue Bees.")
1
2
3
4
output
There are Pink Bees less than Blue Bees.
1
pink_bees = 5
blue_bees = 4
if(pink_bees < blue_bees):
	print("There are Pink Bees less than Blue Bees.")
1
2
3
4
output




 
 

pink_bees = 5
blue_bees = 4
if(pink_bees < blue_bees):
	print("There are Pink Bees less than Blue Bees.")
else:
	print("There are Pink Bees more than Blue Bees.")
1
2
3
4
5
6
output
There are Pink Bees more than Blue Bees.
1