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:
age = 25
price = 19.99
is_online = True
These four variables do not store the same kind of data.
"Alice"is a string25is an integer19.99is a floatTrueis 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)
These do not represent the same type.
"10"is text10is a number
That distinction matters immediately. This works:
But this causes a problem:
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:
city = “Berlin”
message = “Learning Python is useful”
Strings can use double quotes or single quotes:
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:
Or by using a variable:
print(greeting)
Joining strings
Strings can be combined using +:
last_name = “Smith”
full_name = first_name + ” “ + last_nameprint(full_name)
Output:
This is called string concatenation.
Repeating strings
Python can also repeat strings with *:
Output:
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:
This fails because Python thinks Alice is a variable name, not text.
Correct version:
Another common mistake is mixing strings and numbers incorrectly:
print(“Age: “ + age)
This causes a type error because you are trying to combine text and an integer directly with +.
One solution is conversion:
print(“Age: “ + str(age))
Another, cleaner beginner-friendly solution is:
print(“Age:”, age)
Integers in Python
An integer is a whole number without a decimal part.
Examples:
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:
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:
This works, but note that / may return a float even when dividing whole numbers exactly.
Updating integers
Integers are often updated in programs:
count = count + 1
print(count)
Output:
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:
print(age + 1)
This fails because input() returns a string, not an integer.
Correct version:
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:
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:
b = 2.0print(a + b)
print(a – b)
print(a * b)
print(a / b)
Python can also mix integers and floats in expressions:
Output:
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:
price = 10.0
These may look similar, but they are not the same type.
10is an integer10.0is a float
Converting to float
If you want to turn text input into a decimal number, use float():
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:
If the user types 182.5, this raises an error.
Correct version:
Booleans in Python
A boolean is a value that is either True or False.
Examples:
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:
This is one of the main reasons booleans matter so much. They control logic.
Boolean expressions
Booleans often come from comparisons:
print(age >= 18)
Output:
Here, Python evaluates the comparison and produces a boolean result.
Other examples:
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:
This is a string, not a boolean.
Correct boolean version:
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(42))
print(type(3.14))
print(type(True))
Typical output will show:
strfor stringsintfor integersfloatfor floatsboolfor booleans
You can also check variables:
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 conversionint()for integer conversionfloat()for float conversionbool()for boolean conversion
Convert integer to string
text_age = str(age)
print(“Age: “ + text_age)
Convert string to integer
year_number = int(year)
print(year_number + 1)
Convert string to float
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:
print(type(value))
No matter what the user types, Python initially treats it as text.
That means:
stores a string, not an integer.
If you want numeric behavior, convert it:
or:
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
This works because integers and floats are both numeric types.
Invalid mixed string and integer example
This fails because text and number types are not automatically combined here.
Corrected version
or:
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:
Output:
But for strings, + means joining:
Output:
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
print(favorite_language)
Integer example
print(tabs_open)
Float example
print(screen_size)
Boolean example
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
print(price + 5)
This fails because price is text, not a numeric float.
Forgetting to convert input
print(age + 1)
Again, this fails because age is a string.
Using quotes around booleans
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:
10isint10.0isfloat
Mixing incompatible operations
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
age = 31
height = 180.5
is_student = Falseprint(name)
print(age)
print(height)
print(is_student)
Example 2: Check types
print(type(100))
print(type(9.99))
print(type(True))
Example 3: Convert input to integer
print(age + 1)
Example 4: Convert input to float
print(price)
Example 5: Create a boolean from a comparison
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
TrueorFalse input()returns a string by defaulttype()helps you inspect data typesint(),float(), andstr()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.
Get the weekly RF & IT briefing
Radio guides, RF calculators, AI, Windows, Linux and satellite communication explainers. One useful email per week. No spam.
