By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Python programs work with different kinds of data: text, numbers, and more. Python needs to know what type each piece of data is so it can handle it correctly. A string behaves differently from a number, and trying to add them together without understanding the distinction will cause errors. You'll run into type mismatches constantly when you start coding, so understanding the core data types and how to convert between them is essential.
A string is text data, enclosed in quotes. Python gives you built-in methods to manipulate strings without writing complex logic yourself.
msg = " Hello, Python! "
print(msg.strip()) # "Hello, Python!"
print(msg.lower()) # " hello, python! "
print(msg.replace("Python","World")) # " Hello, World! "
print(len(msg)) # 17
# f-strings (the modern way to format)
name, score = "Alice", 98
print(f"{name} scored {score}/100")The strip() method removes whitespace from both ends—useful when cleaning up user input. The lower() method converts to lowercase but leaves the spacing intact. The replace() method finds one substring and swaps it for another. The len() function counts characters, including spaces and punctuation.
For combining strings with variables, f-strings are the modern approach. You put an f before the opening quote, then wrap variables in curly braces. Python evaluates the expression inside the braces and inserts the result into the string. This is cleaner and faster than older formatting methods.
Python handles two main numeric types: integers (whole numbers) and floats (decimals). The operators you use depend on what result you need.
x, y = 10, 3
print(x + y) # 13
print(x // y) # 3 floor division
print(x % y) # 1 modulo (remainder)
print(x ** y) # 1000 exponentiationThe first three operations are straightforward. Floor division (//) rounds down to the nearest integer. Modulo (%) gives you the remainder after division—handy for checking if a number is even or odd, or for cycling through sequences. Exponentiation (**) raises a number to a power.
Data often arrives in the wrong type. A user types their age into a form, but it comes in as text. You need to convert it to an integer before doing math. Python provides conversion functions for this.
age = int("25") # str → int
price = float("9.99") # str → float
label = str(42) # int → strThe int() function converts a string or float to an integer. The float() function converts a string or integer to a decimal. The str() function converts any type to a string. These conversions work as long as the data makes sense—you can't convert the string "abc" to an integer.
Remember: input() always returns a string. Convert before doing math.
This is a common pitfall. When you use input() to get data from a user, Python treats it as text no matter what the user types. If you try to add two inputs together without converting them, you'll concatenate strings instead of adding numbers. Always check what type you're working with.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.