All Courses
Python Basics

Python Data Types

1. What is a Data Type?

  • A way of classifying information
  • Important because programs constantly store, manipulate, and change data
  • Knowing the type determines how you can interact with that data
  • Python's data types differ from other languages (C++, Java, JavaScript) — some similarities but also unique behavior

2. The 5 Core Data Types in Python

1. int — Integer

  • Any whole number with no decimal point
  • Can be positive, negative, or zero
  • Examples: 6, 9, -9, 0, 1000000

2. float — Floating Decimal

  • Any number that contains a decimal point
  • Examples: 2.3, 4.5, 0.5, 2.0, -0.9
  • 2.0 is a float, not an int — because it has a decimal point
  • You can omit the leading zero: .3 and -.9 are valid floats

3. str — String

  • A sequence of characters surrounded by single ' or double " quotes
  • Can contain letters, numbers, spaces, special characters — anything
  • The quotes are what make it a string
  • Examples: "hello", 'world', "2" ← this is a string, not an int!
  • Single vs double quotes doesn't matter — both produce a string

4. bool — Boolean

  • Only two possible values: True or False
  • Capital first letter is requiredtrue / false (lowercase) are NOT booleans
  • Conceptually similar to binary: False = 0, True = 1

5. None — NoneType

  • The keyword None is the only value of this type
  • Used to represent emptiness, nothing, or a placeholder
  • Common use: default value for variables before they're assigned

3. Cheat Sheet Table

Data Type Keyword Example Values
Integer int 6, -9, 0
Float float 2.3, 0.5, -0.9, .3
String str "hello", 'world', "2"
Boolean bool True, False
Nothing None None

4. Useful Built-in Functions

print()

  • Outputs a value to the console
print("hello")   # hello
print(4)         # 4

type()

  • Returns the data type of any value
  • Wrap with print() to see the result
print(type(True))    # <class 'bool'>
print(type("hello")) # <class 'str'>
print(type(2))       # <class 'int'>
print(type(2.7))     # <class 'float'>
print(type(None))    # <class 'NoneType'>

Ignore the <class ...> wrapper for now — just focus on the type name inside


5. Key Takeaways & Recap

  1. Every piece of data in Python has a type
  2. The type controls how you can work with that data
  3. "2" (string) ≠ 2 (int) — quotes always win
  4. True/False must be capitalized to be booleans
  5. None is its own special type representing "nothing"