Python Data Types

If you’re learning Python, you’ve probably heard people talk about data types. Strings, integers, booleans, floats… all the usual suspects. But instead of reading dry definitions, let’s walk through a real script and break down what each part actually does.
This is the exact kind of hands-on learning that makes everything click.
Starting With Strings
Strings are just text. And Python gives you multiple ways to create them.
Literal assignment:
first = "Dave"
last = "Gray"
Here, Python automatically knows these are strings.
There’s also a constructor:
pizza = str("Pepperoni")
Both ways do the same thing. Most developers stick to the first one since it’s cleaner.
Concatenation and Updating Strings
You can combine strings using +:
fullname = first + " " + last
print(fullname)
You can even update an existing string:
fullname += "!"
Casting Numbers Into Strings
If you want to mix text with numbers, cast them:
decade = str(1980)
statement = "I like rock music from the " + decade + "s."
Multiline Strings
Python makes long text easy with triple quotes:
multiline = '''
Hey, how are you?
I was just checking in.
All good?
'''
Escaping Special Characters
When a string includes quotes, tabs, newlines, or slashes:
sentence = 'I'm back at work!tHey!nnWhere's this at\located?'
Single quotes inside single-quoted strings need escaping. Tabs use t, newlines use n.
Useful String Methods
Want lowercase or uppercase?
first.lower()
first.upper()
Want to replace text?
multiline.replace("good", "ok")
Need formatted spacing?
Python gives you ljust, rjust, and center, which are perfect for simple CLI menus:
title = "menu".upper()
print(title.center(20, "="))
String Indexing
Strings act like arrays of characters:
print(first[1]) # second letter
print(first[-1]) # last letter
print(first[1:-1]) # slice
Booleans
Booleans represent True or False values:
myvalue = True
x = bool(False)
They pop up everywhere in conditions, checks, and logic.
Numbers in Python
Integers
Whole numbers:
price = 100
best_price = int(80)
Floats
Decimals:
gpa = 3.28
Complex Numbers
Used for advanced math:
comp_value = 5 + 3j
You can access the real and imaginary parts:
comp_value.real
comp_value.imag
Common Math Functions
abs(gpa)
round(gpa)
round(gpa, 1)
math.sqrt(64)
math.ceil(gpa)
math.floor(gpa)
Python makes numeric calculations ridiculously simple.
Casting Strings to Numbers
You can safely convert numeric strings:
zipcode = "10001"
zip_value = int(zipcode)
But if you try converting non-numeric text:
int("New York")
Python will throw an error, as it should.
Conclusion
This script is a great example of how Python handles different data types in everyday code. Strings, numbers, booleans, casting, formatting, math operations — they all show up constantly when you’re building real programs. Once you’re comfortable with these basics, writing clean and reliable Python becomes much easier.
For more visit this repo
Happy coding!!
Python Data Types was originally published in Javarevisited on Medium, where people are continuing the conversation by highlighting and responding to this story.
This post first appeared on Read More

