Python data types: strings, integers, floats, and booleans

Once you understand variables, the next step is understanding the kinds of values those variables can store. In Python, every value has a data type. That type affects how the value behaves, what operations you can perform on it, and how Python interprets it internally. For a beginner, this is one of the most important foundations in the language, because many early mistakes come from using the wrong type or assuming two values behave the same when they do not.

If you store a person’s name, Python treats it differently than a price, a temperature, or a true-or-false setting. That difference is not just technical detail. It directly affects what your code can do. A number can be added to another number. A string can be joined with another string. A boolean can control a condition. Understanding those distinctions is essential if you want to write Python code that works correctly.

This lesson explains Python data types for beginners, with a focus on the four most important early types: strings, integers, floats, and booleans. These types appear everywhere in beginner-level programming, and once you understand them well, topics like user input, conditions, loops, and functions become much easier.

What is a data type in Python

A data type defines what kind of value something is. In Python, the type determines how the value is stored, how it behaves, and which operations make sense with it.

For example:

name = “Alice”
age = 25
price = 19.99
is_online = True

These four variables do not store the same kind of data.

  • "Alice" is a string
  • 25 is an integer
  • 19.99 is a float
  • True is a boolean

Even though they are all stored in variables, Python handles them differently because their types are different.

This matters because programming is not only about storing values. It is also about doing things with those values. The type influences what is possible.

Why data types matter for beginners

A lot of beginner confusion in Python comes from not recognizing type differences early enough. Two values may look similar on the screen but behave very differently in code.

For example:

print(“10”)
print(10)

These do not represent the same type.

  • "10" is text
  • 10 is a number

That distinction matters immediately. This works:

print(10 + 5)

But this causes a problem:

print(“10” + 5)

The reason is that Python does not treat text and numbers as interchangeable by default.

If you understand types early, you make fewer mistakes and you debug faster. You also start to see Python more clearly as a system of structured values rather than just lines of text.

The four core Python data types beginners should learn first

In the early stage of learning Python, four data types appear constantly:

  • strings
  • integers
  • floats
  • booleans

These types are enough for many beginner programs. They also form the basis for understanding more advanced types later.

Strings in Python

A string is a sequence of text characters. In Python, strings are written inside quotation marks.

Examples:

first_name = “Emma”
city = “Berlin”
message = “Learning Python is useful”

Strings can use double quotes or single quotes:

language = “Python”
country = ‘Hungary’

Both are valid. The important thing is that the opening and closing quotes match correctly.

Why strings matter

Strings are everywhere in programming. They are used for:

  • names
  • messages
  • file paths
  • email addresses
  • product titles
  • user input
  • labels
  • text processing

Any time you are working with words, sentences, or symbols treated as text, you are probably working with strings.

Printing strings

You can print a string directly:

print(“Hello, world!”)

Or by using a variable:

greeting = “Hello, world!”
print(greeting)

Joining strings

Strings can be combined using +:

first_name = “Liam”
last_name = “Smith”
full_name = first_name + ” “ + last_nameprint(full_name)

Output:

Liam Smith

This is called string concatenation.

Repeating strings

Python can also repeat strings with *:

print(“Hi! “ * 3)

Output:

Hi! Hi! Hi!

This shows that strings are not just passive text. They support operations too, but those operations are different from numeric operations.

Common beginner mistakes with strings

One common mistake is forgetting quotation marks:

name = Alice

This fails because Python thinks Alice is a variable name, not text.

Correct version:

name = “Alice”

Another common mistake is mixing strings and numbers incorrectly:

age = 25
print(“Age: “ + age)

This causes a type error because you are trying to combine text and an integer directly with +.

One solution is conversion:

age = 25
print(“Age: “ + str(age))

Another, cleaner beginner-friendly solution is:

age = 25
print(“Age:”, age)

Integers in Python

An integer is a whole number without a decimal part.

Examples:

age = 30
year = 2026
quantity = 5
temperature = 2

Integers can be positive, negative, or zero.

Why integers matter

Integers are used whenever you need exact whole-number values such as:

  • age
  • count
  • quantity
  • year
  • score
  • index position
  • number of items

They are one of the most common types in beginner Python programs.

Arithmetic with integers

Integers support standard arithmetic operations:

a = 10
b = 3print(a + b)
print(a b)
print(a * b)
print(a // b)
print(a % b)
print(a ** b)

These operators mean:

  • + addition
  • - subtraction
  • * multiplication
  • // floor division
  • % remainder
  • ** exponentiation

You can also use normal division:

print(10 / 2)

This works, but note that / may return a float even when dividing whole numbers exactly.

Updating integers

Integers are often updated in programs:

count = 1
count = count + 1
print(count)

Output:

2

This pattern is very common in counters, loops, and score tracking.

Common beginner mistakes with integers

A common mistake is treating text input as if it were already an integer:

age = input(“Enter your age: “)
print(age + 1)

This fails because input() returns a string, not an integer.

Correct version:

age = int(input(“Enter your age: “))
print(age + 1)

This converts the input into an integer before using it in arithmetic.

Floats in Python

A float is a number with a decimal point. Python uses floats for values that are not whole numbers.

Examples:

price = 19.99
height = 182.5
temperature = 21.3
weight = 74.8

Why floats matter

Floats are used for measurements, prices, averages, percentages, and other values where fractions matter.

Typical beginner examples include:

  • product prices
  • body height
  • distance
  • speed
  • average scores
  • scientific values

Arithmetic with floats

Floats work much like integers in arithmetic:

a = 5.5
b = 2.0print(a + b)
print(a b)
print(a * b)
print(a / b)

Python can also mix integers and floats in expressions:

print(10 + 2.5)

Output:

12.5

Why beginners need to distinguish integers and floats

The main difference is that integers are whole numbers, while floats include decimal values. This matters because some operations behave differently, and some contexts require one type more naturally than the other.

For example:

count = 10
price = 10.0

These may look similar, but they are not the same type.

  • 10 is an integer
  • 10.0 is a float

Converting to float

If you want to turn text input into a decimal number, use float():

price = float(input(“Enter the price: “))
print(price)

This is important because many beginner programs involve decimal values from the user.

Common beginner mistakes with floats

One common error is assuming all numeric input should become int. That works for whole numbers but fails for decimal values:

height = int(input(“Enter your height: “))

If the user types 182.5, this raises an error.

Correct version:

height = float(input(“Enter your height: “))

Booleans in Python

A boolean is a value that is either True or False.

Examples:

is_logged_in = True
has_access = False
is_admin = True

Boolean values are especially important in conditions and decision-making.

Why booleans matter

Booleans are used whenever the answer is yes or no, on or off, true or false.

They commonly represent things like:

  • whether a user is logged in
  • whether a file exists
  • whether access is allowed
  • whether a product is available
  • whether a condition is met

Using booleans in conditions

Example:

is_logged_in = True

if is_logged_in:
print(“Welcome back”)

If the value is True, the code inside the if block runs.

Another example:

has_access = False

if has_access:
print(“Access granted”)
else:
print(“Access denied”)

Output:

Access denied

This is one of the main reasons booleans matter so much. They control logic.

Boolean expressions

Booleans often come from comparisons:

age = 20
print(age >= 18)

Output:

True

Here, Python evaluates the comparison and produces a boolean result.

Other examples:

print(5 > 2)
print(10 == 3)
print(7 != 4)

These expressions return True or False.

Common beginner mistakes with booleans

A common mistake is writing boolean values as strings instead of actual booleans:

is_online = “True”

This is a string, not a boolean.

Correct boolean version:

is_online = True

That distinction matters because a string and a boolean behave differently in logic.

How to check a value’s type in Python

Python provides a built-in function called type() that shows the type of a value.

Examples:

print(type(“Python”))
print(type(42))
print(type(3.14))
print(type(True))

Typical output will show:

  • str for strings
  • int for integers
  • float for floats
  • bool for booleans

You can also check variables:

name = “Olivia”
age = 28
price = 12.5
is_member = Falseprint(type(name))
print(type(age))
print(type(price))
print(type(is_member))

This is very useful for beginners when something behaves unexpectedly.

Type conversion in Python

Sometimes you need to convert one type into another. This is called type conversion.

Common conversion functions include:

  • str() for string conversion
  • int() for integer conversion
  • float() for float conversion
  • bool() for boolean conversion

Convert integer to string

age = 25
text_age = str(age)
print(“Age: “ + text_age)

Convert string to integer

year = “2026”
year_number = int(year)
print(year_number + 1)

Convert string to float

price = “19.99”
price_number = float(price)
print(price_number)

Type conversion is one of the most important practical skills for beginners because input and output often require it.

Why input() creates strings by default

This is a very important beginner concept. The input() function always returns a string.

Example:

value = input(“Enter something: “)
print(type(value))

No matter what the user types, Python initially treats it as text.

That means:

age = input(“Enter your age: “)

stores a string, not an integer.

If you want numeric behavior, convert it:

age = int(input(“Enter your age: “))

or:

price = float(input(“Enter the price: “))

A large number of beginner bugs come from forgetting this rule.

Mixing data types in Python

Sometimes Python allows different types to interact, and sometimes it does not.

Valid mixed numeric example

print(10 + 2.5)

This works because integers and floats are both numeric types.

Invalid mixed string and integer example

print(“10” + 5)

This fails because text and number types are not automatically combined here.

Corrected version

print(int(“10”) + 5)

or:

print(“10” + str(5))

These do different things:

  • first version performs numeric addition
  • second version performs string concatenation

That distinction is essential.

How data types affect operations

The same symbol can behave differently depending on the type.

For example, + means addition for numbers:

print(3 + 4)

Output:

7

But for strings, + means joining:

print(“Py” + “thon”)

Output:

Python

This is why data types matter. Python does not only look at the operator. It also looks at the values involved.

Real beginner examples with data types

Here are some practical examples of the four main data types.

String example

favorite_language = “Python”
print(favorite_language)

Integer example

tabs_open = 12
print(tabs_open)

Float example

screen_size = 15.6
print(screen_size)

Boolean example

is_ready = True
print(is_ready)

These are all simple, but they reflect real program behavior: storing text, quantities, measurements, and logical states.

Common beginner mistakes with Python data types

Several mistakes appear again and again when beginners work with types.

Mistaking text for numbers

price = “19.99”
print(price + 5)

This fails because price is text, not a numeric float.

Forgetting to convert input

age = input(“Enter your age: “)
print(age + 1)

Again, this fails because age is a string.

Using quotes around booleans

is_active = “False”

This creates a string, not a boolean.

Assuming 10 and 10.0 are the same type

They are numerically similar, but they are not the same type:

  • 10 is int
  • 10.0 is float

Mixing incompatible operations

name = “Alice”
print(name 1)

This does not make sense for the string type, so Python raises an error.

Why mastering data types helps with every later topic

Data types are not an isolated beginner lesson. They affect almost every topic that comes after.

  • variables store typed values
  • input returns strings
  • conditions often depend on booleans
  • arithmetic depends on numeric types
  • loops may update integers
  • functions accept and return values of different types
  • file handling often works with strings
  • debugging often requires checking type mismatches

That is why this lesson matters more than it may seem. If you understand strings, integers, floats, and booleans clearly, the rest of beginner Python becomes much more stable.

Small practice examples

Example 1: Store one value of each type

name = “Daniel”
age = 31
height = 180.5
is_student = Falseprint(name)
print(age)
print(height)
print(is_student)

Example 2: Check types

print(type(“Hello”))
print(type(100))
print(type(9.99))
print(type(True))

Example 3: Convert input to integer

age = int(input(“Enter your age: “))
print(age + 1)

Example 4: Convert input to float

price = float(input(“Enter the price: “))
print(price)

Example 5: Create a boolean from a comparison

score = 85
passed = score >= 50
print(passed)

What you should understand before moving on

Before continuing to the next lesson, you should be comfortable with the following:

  • strings are text values
  • integers are whole numbers
  • floats are decimal numbers
  • booleans are True or False
  • input() returns a string by default
  • type() helps you inspect data types
  • int(), float(), and str() can convert values
  • operations depend on the type involved
  • text and numbers are not automatically interchangeable

If these points feel clear, the next topic becomes much easier, because user input relies heavily on type awareness.

Python data types define what kind of value a variable holds and how that value behaves. For beginners, the four most important early types are strings, integers, floats, and booleans. These cover text, whole numbers, decimal values, and true-or-false logic, which together form the basis of most beginner Python programs.

Understanding these data types is essential because they affect everything from arithmetic and output to user input and program logic. Many beginner mistakes come from mixing types incorrectly or forgetting to convert values when needed. Once you understand how each type works, Python becomes far easier to predict, debug, and use effectively.

The next step in the course is usually user input, where these type concepts become even more practical, because input values often need to be stored, checked, and converted before they can be used correctly.


Image(s) used in this article are either AI-generated or sourced from royalty-free platforms like Pixabay or Pexels.

This article may contain affiliate links. If you purchase through these links, we may earn a commission at no extra cost to you.

Weekly briefing

Get the weekly RF & IT briefing

Radio guides, RF calculators, AI, Windows, Linux and satellite communication explainers. One useful email per week. No spam.

Similar Posts