Lesson 03 — Python Data Types
Lesson 03 — Python Data Types
Section titled “Lesson 03 — Python Data Types”Lesson Overview
Section titled “Lesson Overview”Imagine you’re building a cloud automation script.
The script needs to store:
- A server name
- The number of virtual machines
- CPU utilization
- Whether a server is running
- A list of AWS regions
- A collection of IAM users
- Configuration settings
Each piece of information is different.
Some are numbers.
Some are text.
Some are either True or False.
Some are collections of values.
Python stores these different kinds of information using Data Types.
Choosing the correct data type makes programs easier to understand, more efficient, and less prone to errors.
Learning Objectives
Section titled “Learning Objectives”After completing this lesson, you will be able to:
- Understand Python data types.
- Work with numbers and strings.
- Use Boolean values.
- Learn Lists, Tuples, Dictionaries, and Sets.
- Convert between data types.
- Inspect variable types.
- Apply data types in real-world IT automation.
What is a Data Type?
Section titled “What is a Data Type?”A Data Type defines the kind of value a variable can store.
Examples include:
- Numbers
- Text
- True or False values
- Collections of data
Python automatically determines the data type based on the value assigned.
Why Data Types Matter
Section titled “Why Data Types Matter”Choosing the correct data type helps you:
- Store information efficiently.
- Perform calculations.
- Compare values.
- Process collections of data.
- Write reliable automation scripts.
Almost every Python program uses multiple data types.
Common Python Data Types
Section titled “Common Python Data Types”| Data Type | Example | Purpose |
|---|---|---|
| int | 100 | Whole Numbers |
| float | 95.5 | Decimal Numbers |
| str | “AWS” | Text |
| bool | True | True or False |
| list | [“EC2”,“S3”] | Ordered Collection |
| tuple | (“AWS”,“Azure”) | Fixed Collection |
| dict | {“Region”:“Mumbai”} | Key-Value Pairs |
| set | {“SSH”,“HTTPS”} | Unique Values |
Integer (int)
Section titled “Integer (int)”Integers represent whole numbers.
Example:
servers = 10
users = 250
ports = 443Integers are commonly used for:
- Port Numbers
- User Counts
- CPU Cores
- Memory Size
- Number of Resources
Floating Point Numbers (float)
Section titled “Floating Point Numbers (float)”Floats represent decimal values.
Example:
cpu = 73.6
memory = 82.4Common uses include:
- CPU Utilization
- Storage Usage
- Temperature
- Network Latency
- Pricing
Strings (str)
Section titled “Strings (str)”Strings store text.
Example:
cloud = "AWS"
name = "GoHackersCloud"Strings are enclosed using:
" "
' 'Strings are one of the most frequently used data types.
Multi-Line Strings
Section titled “Multi-Line Strings”Python supports multi-line strings.
Example:
message = """Welcome toGoHackersCloud Academy"""Useful for documentation and long messages.
Boolean (bool)
Section titled “Boolean (bool)”Booleans represent two possible values.
True
FalseExample:
server_running = True
vpn_connected = FalseBooleans are heavily used in decision-making.
Boolean Example
Section titled “Boolean Example”logged_in = True
print(logged_in)Output:
TrueLists store multiple values in a specific order.
Example:
clouds = ["AWS", "Azure", "GCP"]Access an item:
print(clouds[0])Output:
AWSLists are mutable, meaning they can be changed after creation.
Adding Items to a List
Section titled “Adding Items to a List”clouds.append("Oracle Cloud")Updated list:
AWS
Azure
GCP
Oracle CloudTuples
Section titled “Tuples”Tuples also store multiple values.
Example:
regions = ("Mumbai", "London", "Tokyo")Unlike lists, tuples are immutable.
Once created, they cannot be modified.
Tuples are useful for storing fixed configuration values.
Dictionaries
Section titled “Dictionaries”A Dictionary stores data as Key : Value pairs.
Example:
server = {
"Name": "WebServer01",
"OS": "Windows",
"Status": "Running"
}Retrieve a value:
print(server["OS"])Output:
WindowsDictionaries are widely used in APIs and cloud automation.
Sets store unique values.
Example:
ports = {80, 443, 22}Duplicate values are automatically removed.
Example:
{22,22,80,443}Becomes:
{22,80,443}Sets are useful for removing duplicates.
None Type
Section titled “None Type”Python has a special value:
NoneExample:
response = NoneThis means:
No value has been assigned yet.
Checking Data Types
Section titled “Checking Data Types”Use the type() function.
Example:
name = "Python"
print(type(name))Output:
<class 'str'>Another example:
age = 25
print(type(age))Output:
<class 'int'>Type Conversion
Section titled “Type Conversion”Python allows conversion between data types.
Convert String to Integer:
age = int("25")Convert Integer to String:
age = str(25)Convert Integer to Float:
price = float(100)Type conversion is common when processing user input.
User Input Example
Section titled “User Input Example”age = int(input("Enter Age: "))
print(age + 5)Without int(), Python treats input as text.
String Concatenation
Section titled “String Concatenation”Join strings together.
Example:
first = "Cloud"
second = "Engineer"
print(first + " " + second)Output:
Cloud EngineerNumeric Operations
Section titled “Numeric Operations”a = 20
b = 5
print(a + b)
print(a - b)
print(a * b)
print(a / b)Output:
25
15
100
4.0Data Types in Cloud Computing
Section titled “Data Types in Cloud Computing”Cloud Engineers commonly store:
instance_name = "WebServer01"
cpu = 45.8
running = True
regions = ["Mumbai","London"]
config = {
"Region":"Mumbai",
"Instance":"t3.micro"
}Automation scripts rely heavily on dictionaries and lists.
Data Types in Cybersecurity
Section titled “Data Types in Cybersecurity”Security professionals work with:
- IP Addresses
- Usernames
- Event IDs
- Log Entries
- Port Numbers
- Alerts
- JSON Responses
Example:
event = {
"EventID":4625,
"Status":"Failed Login"
}Data Types in AI
Section titled “Data Types in AI”Machine Learning applications use:
- Numbers
- Lists
- Dictionaries
- Matrices
- DataFrames
Every AI model begins with structured data.
Common Mistakes
Section titled “Common Mistakes”Beginners often:
- Forget quotation marks around strings.
- Try adding numbers to strings.
- Use the wrong data type.
- Modify tuples.
- Misspell dictionary keys.
Understanding data types helps prevent these errors.
Real-World Example
Section titled “Real-World Example”A cloud inventory script stores information about virtual machines.
server = {
"Name":"WebServer01",
"CPU":45.5,
"Running":True,
"Services":["HTTP","HTTPS"],
"Region":"Mumbai"
}Each value uses a different data type to represent the appropriate kind of information.
Best Practices
Section titled “Best Practices”As a Python developer:
- Choose the correct data type for each variable.
- Use dictionaries for structured data.
- Use lists for collections that change.
- Use tuples for fixed values.
- Use meaningful variable names.
- Verify data types with
type(). - Convert user input before calculations.
- Keep data structures simple and readable.
Choosing the right data type improves code quality and maintainability.
Key Takeaways
Section titled “Key Takeaways”After completing this lesson, you should understand:
- Integer
- Float
- String
- Boolean
- List
- Tuple
- Dictionary
- Set
- None
- Type Conversion
type()Function
Summary
Section titled “Summary”Python Data Types are the foundation of every Python program.
By understanding how to store numbers, text, logical values, and collections of data, you’ll be able to build reliable automation scripts, cloud applications, cybersecurity tools, and AI solutions.
Mastering data types is one of the most important steps toward becoming an effective Python developer.
Next Lesson
Section titled “Next Lesson”➡️ Lesson 04 — Python Functions
In the next lesson, you’ll learn how to create reusable blocks of code using functions, understand parameters, arguments, return values, variable scope, and build modular Python programs that are easier to maintain and scale.