Sign in

Intro to Computer Science / Unit 4: Programming Basics in Python

4.2 Data Types

3 practice questionsNot yet reviewed

Notes

Every value has a data type. The main ones are:

TypeMeaningExample
intwhole number42
floatnumber with a decimal point3.14
strtext in quotes"hello"
boolTrue or FalseTrue
  • Use type(x) to see the type of a value.
  • "5" (with quotes) is a string, not a number, so "5" + "5" gives "55".
  • Convert with int(), float() and str(): int("7") gives 7.

Practice

What is the type of the value 3.0?
What does print("4" + "6") display?
What does print(int("12") + 3) display?

Ready for more? Take the Unit 4 test.