As discussed in the previous article on the variables about the need of programming languages to store information. This article will be about how the different data is stored. Let’s slow it down a bit and really think about it. If storage is where data lives… then data types are basically how that data is shaped inside memory. And depending on the language you’re using, that “shape” changes a lot. Primitive data types are the most basic building blocks used to represent values inside a program.
When learning both Python and Go, understanding their primitive data types is one of the fastest ways to understand the design philosophy behind each language.
Understanding Primitive Data Types
Primitive data types are the simplest forms of data a programming language can handle directly. They represent single values such as:
- Text
- Numbers
- Boolean values (true or false)
- Fixed constant values
Text and Characters
Strings in Python
In Python, text is represented using the str data type. A string, simply put, is a sequence of characters enclosed in quotation marks.
name = "Michael"
message = 'Hello World'
Python treats strings as Unicode by default, meaning they can store characters from different languages and symbols.
emoji = "😊"
language = "Python"
One of Python’s strengths is how simple string manipulation feels.
first_word = "Go"
last_word = "Python"
full_word = first_word + " " + last_word
print(full_word)
Output:
Go Python
Python does not have a separate character (char) data type. A single character is simply considered a string of length one.
letter = "A"
print(type(letter))
Output:
<class 'str'>
This design keeps the language simpler because developers only need to think about one text type instead of multiple character-based types.
Strings and Runes in Go
Go also uses strings for textual data.
package main
import "fmt"
func main() {
name := "Michael"
fmt.Println(name)
}
But Go handles characters differently from Python.
In Go:
- A string represents a sequence of bytes.
- A rune represents a single Unicode character.
A rune is actually an alias for int32.
var letter rune = 'A'
Notice something important:
- Strings use double quotes
" " - Runes use single quotes
' '
This distinction is very important in Go.
package main
import "fmt"
func main() {
var character rune = 'G'
fmt.Println(character)
}
Output:
71
The output is numeric because Go stores runes internally using Unicode code points.
To print the actual character:
fmt.Printf("%cn", character)
Output:
G
Go’s approach gives developers more control over memory and encoding behavior, especially for systems programming and high-performance applications.
Numbers
Numbers are another core primitive data type.
Both Python and Go support:
- Integers
- Floating-point numbers
Integers and Floats in Python
Python makes numeric programming simple.
age = 25
price = 19.99
Python automatically determines the type.
print(type(age))
print(type(price))
Output:
<class 'int'>
<class 'float'>
One important feature of Python is that integers can grow very large automatically.
big_number = 999999999999999999999999999999
Python dynamically allocates memory for large integers behind the scenes.
This flexibility is convenient because developers rarely worry about integer overflow or memory size during basic programming.
Integers and Floats in Go
Go is stricter and more explicit.
var age int = 25
var price float64 = 19.99
Go supports multiple integer sizes:
-
int8 -
int16 -
int32 int64
And floating-point types:
-
float32 float64
Example:
var smallNumber int8 = 100
var largeNumber int64 = 9000000000
This explicit sizing is important because each type uses a specific amount of memory.
| Type | Size |
|---|---|
| int8 | 8 bits |
| int16 | 16 bits |
| int32 | 32 bits |
| int64 | 64 bits |
Go forces developers to think more carefully about memory usage and performance.
For example:
var x int32 = 10
var y int64 = 20
// This causes an error
// fmt.Println(x + y)
Go does not automatically mix different integer sizes. Developers must explicitly convert types.
fmt.Println(int64(x) + y)
This strictness reduces accidental bugs and improves predictability in large systems.
Booleans
Booleans represent logical truth values.
They are heavily used in:
- Conditions
- Comparisons
- Decision-making statements
Booleans in Python
Python uses:
True and False
Notice the capitalization.
is_logged_in = True
is_admin = False
Example:
age = 20
if age >= 18:
print(True)
Output:
True
Python’s boolean system is highly flexible because many values can behave as truthy or falsy.
Examples of falsy values:
0
None
""
[]
False
Everything else is generally considered truthy.
Booleans in Go
Go also supports boolean values, but with stricter rules(as usual).
var isLoggedIn bool = true
var isAdmin bool = false
Notice the lowercase keywords:
true and false
Go does not allow non-boolean values in conditional statements.
This is invalid:
var number int = 1
if number {
fmt.Println("Hello")
}
Python allows similar truthy checks, but Go requires an actual boolean expression.
Correct Go example:
if number == 1 {
fmt.Println("Hello")
}
This design improves clarity and reduces ambiguity.
Constants
Constants are values that should never change during program execution.
Constants in Python
Python does not have a true constant keyword. Instead, developers follow a naming convention using uppercase variable names.
PI = 3.14159
MAX_USERS = 100
However, Python does not enforce immutability.
PI = 10
This still works. The uppercase naming style simply communicates intent to other developers. Python relies heavily on developer discipline and readability conventions.
Constants in Go
Go provides an actual const keyword.
const Pi = 3.14159
const MaxUsers = 100
Once declared, constants cannot be modified.
const Age = 20
// Error
// Age = 30
This enforcement makes programs safer and more predictable. Go constants can also exist without explicitly specifying a type.
const Name = "GoLang"
The compiler determines the appropriate type automatically.
Conclusion
In Python, primitive types are designed to feel natural and easy to use. Developers can move quickly without worrying much about memory sizes or strict typing rules.
In Go, primitive types are more structured and explicit. Developers are expected to think carefully about memory, type safety, and predictability.
Comment , Share and Like, thanks for reading.
Top comments (0)