{}const=>[]async()letfn</>var
DevelopmentBasics

Data Types in Programming: A Complete Guide for Beginners

A detailed guide to basic data types in programming. You will learn what numbers, strings and logical values are, how to work with them, what operations can be performed and how to avoid typical mistakes. The article is written in simple language with many practical examples in Python.

К

Kodik

Author

5 min read

What are data types and why do we need them?

The data type determines what kind of information the variable stores and what operations can be performed with it. It's like containers of different shapes: some can hold liquid, others can hold solid objects, and others are suitable for something specific.

Understanding data types helps you avoid mistakes and write more efficient code. For example, you cannot add a number and text without a special conversion, just as you cannot pour water into a colander.

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

Numbers

The numeric data type is used to store numeric values. In most programming languages, there are two main subtypes of numbers:

Integers are numbers without a fractional part:

возраст = 25
количество_товаров = 100
температура = -5

Floating-point numbers are numbers with a fractional part:

цена = 99.99
пи = 3.14159
температура_точная = 36.6

Operations with numbers

You can perform mathematical operations with numbers:

# Addition
сумма = 10 + 5  # 15

# Subtraction
разность = 10 - 5  # 5

# Multiplication
произведение = 10 * 5  # 50

# Division
частное = 10 / 5  # 2.0

# Exponentiation
степень = 2 ** 3  # 8

# Remainder of division
остаток = 10 % 3  # 1

It is important to remember: when dividing integers in many languages, the result can be a fractional number, even if it is divisible by a whole number.

Strings

Strings are used to store text information. It can be a single letter, a word, a sentence, or an entire text.

Strings are usually enclosed in quotation marks — single or double:

имя = "Maria"
приветствие = 'Hello, world!'
адрес = "10 Pushkin Street"

Working with strings

Concatenation (string joining):

имя = "Alexey"
фамилия = "Ivanov"
полное_имя = имя + " " + фамилия  # "Alexey Ivanov"

Line length:

текст = "Programming"
длина = len(текст)  # 16

Reference to symbols:

слово = "Python"
первая_буква = слово[0]  # "P"
последняя_буква = слово[-1]  # "n"

String methods:

текст = "hello world"
верхний_регистр = текст.upper()  # "HELLO WORLD"
замена = текст.replace("world", "Python")  # "hello Python"

Escaping special characters

Sometimes you need to use quotation marks or other special characters in the string. To do this, use a backslash:

цитата = "He said: \"Hello!\""
путь = "C:\\Users\\Documents"
многострочный_текст = "First line\nSecond line"

Boolean values

The logical data type is the simplest type that can only have two values: true or false. It is named after the mathematician George Boole.

is_active = True
has_subscription = False
is_admin = True

Applying logical values

Logical values are most often used in conditional statements:

возраст = 20
совершеннолетний = возраст >= 18  # True

if совершеннолетний:
    print("Access allowed")
else:
    print("Access denied")

Comparison operations

Comparison operations return logical values:

5 > 3    # True (more)
5 < 3    # False (less)
5 == 5   # True (equals)
5 != 3   # True (not equal)
5 >= 5   # True (greater than or equal to)
5 <= 3   # False (less than or equal to)

Logical operations

Logical values can be combined using logical operators:

# AND — true if both conditions are true
True and True   # True
True and False  # False

# OR — true if at least one condition is true
True or False   # True
False or False  # False

# NOT — inverts the value
not True   # False
not False  # True

Practical example:

возраст = 25
имеет_права = True

может_водить = возраст >= 18 and имеет_права  # True

Data type conversion

Sometimes it is necessary to convert data from one type to another. This process is called type casting or conversion.

# String to number
строка_число = "42"
число = int(строка_число)  # 42

# Number in line
возраст = 25
текст_возраст = str(возраст)  # "25"

# String to boolean
булево = bool("True")  # True
пустая_строка = bool("")  # False

# Number to boolean
bool(0)   # False
bool(1)   # True
bool(42)  # True

Important: be careful when converting types, as not all conversions are intuitive. For example, a non-empty string will always be True when converted to a logical type, even if it is a "False" string.

Common mistakes of beginners

Attempt to perform operations with incompatible types:

# Error!
результат = "5" + 5  

# Correct:
результат = int("5") + 5  # 10
# or
результат = "5" + str(5)  # "55"

Using the comparison operator instead of assignment:

# Incorrect:
if возраст = 18:  # Error!

# Correct:
if возраст == 18:

Comparison of strings and numbers:

"10" == 10  # False, because they are different types

Data type validation

In Python, you can check the type of a variable using the type() function:

print(type(42))        # <class 'int'>
print(type(3.14))      # <class 'float'>
print(type("Hello"))   # <class 'str'>
print(type(True))      # <class 'bool'>

Conclusion

Understanding basic data types is the foundation of programming. Numbers allow you to perform calculations, strings work with text, and logical values help you make decisions in the program. As you learn, you will encounter more complex data types such as lists, dictionaries, and objects, but they are all built on these basic concepts.

We recommend learning the basics in Kodik app!

You will find:

  • Interactive lessons with step-by-step explanations

  • Cool practical tasks, which will help to consolidate the material

  • Real projects, where you will use if, else, and elif to create games and useful programs

  • Tasks of different levels of complexity - from simple to advanced

  • Instant code verification and tips if something went wrong

Practice working with different types of data, experiment with transformations and operations. Over time, working with data types will become intuitive, and you will automatically select the appropriate type for each task.

Join our Telegram channel and get communication with like-minded people and support from experienced programmers.

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card