Strings vs Numbers

Slide 2:

You may have noticed that there is a difference between strings and numbers in Python. They look and act differently, and sometimes that can be confusing and mess up your code.

A string is like a sentence, but not completely. It’s just a group of characters surrounded by “ “ marks. It has no meaning to Python. It only has meaning to the person reading it.

Slide 3

There are several different types of numbers in Python- we’ll get to that later.

A number in Python has meaning. That means that Python can interact with it in some way. This is why numbers don’t need “ “ marks.

Python can do operations with numbers (add, subtract, multiply, etc…) because numbers have meaning to Python.

Slide 4

abs() = absolute value of a number

int() = number as an integer

float() = number as a floating point (decimal)

Slide 5

You can put a string together with a number.

If you try this way you’ll get an error because a number can’t be in a string.

Instead use the str() function! This converts your number to a string so it can be printed

Slide 6