惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
博客园 - 司徒正美
罗磊的独立博客
D
Docker
Last Week in AI
Last Week in AI
爱范儿
爱范儿
M
MIT News - Artificial intelligence
V
V2EX
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Security Blog
Microsoft Security Blog
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
V
Visual Studio Blog
博客园 - 叶小钗
B
Blog RSS Feed
A
About on SuperTechFans
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
P
Proofpoint News Feed

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Data Types, Typecasting, eval(), Boolean Logic, Input/Out...
Tejas Shinkar · 2026-06-15 · via DEV Community

Data Types, Typecasting, eval(), Boolean Logic & String Formatting

Today, we explored Python's fundamental and derived data types, typecasting, boolean truthiness, input/output operations, and string formatting. While these topics may seem basic, they're the foundation of every DevOps automation script you'll write.

A surprising realization from today's session was that AWS API responses, Kubernetes objects, Terraform outputs, and JSON payloads all map directly to Python data structures. Understanding these types is not just about learning Python—it's about understanding how automation tools communicate.


Python Data Types Overview

Python data types can broadly be divided into two categories:

Fundamental Types Collection Types
int list
float tuple
complex set
str dict
bool
None

Fundamental Data Types

Integer (int)

Integers represent whole numbers and, unlike many programming languages, Python doesn't impose a practical size limit on them.

port = 22
replicas = 3
exit_code = 0

big_number = 9237093793579275093270937509750937095709327509327095737509375375093275093275

This makes Python particularly convenient when dealing with very large numerical values.

Float (float)

Floats store decimal numbers and are commonly used for thresholds, percentages, prices, and time-related values.

cpu_threshold = 85.5
spot_price = 0.012
disk_usage = 73.6

One thing worth remembering is that Python automatically removes trailing zeros.

10.00

becomes:

10.0

Complex (complex)

Complex numbers are rarely used in DevOps but are supported natively by Python.

a = 3 + 4j

print(a.real)
print(a.imag)

Output:

3.0
4.0

String (str)

Strings represent textual data and can be written using single, double, or triple quotes.

env = 'production'

message = "It's a healthy instance"

terraform_block = '''
resource "aws_instance" "web" {
  ami           = "ami-0abcdef1234"
  instance_type = "t2.micro"
}
'''

A common mistake:

msg = 'It's broken'

This causes a syntax error because the apostrophe terminates the string.

Correct approaches:

msg = "It's fixed"

msg = 'It\'s fixed'

Boolean (bool)

Booleans contain only two possible values.

is_healthy = True
is_scaling = False

Python is case-sensitive:

true
TRUE

Both are invalid.

Only:

True
False

are valid boolean values.

None

None represents the absence of a value.

response = None
instance_id = None

if response is None:
    print("No response from AWS API")

This pattern appears frequently when handling API calls and optional values.


Collection Data Types

These data structures become extremely important when working with cloud services and automation tools.

List

Lists are ordered, mutable, and allow duplicate values.

servers = ['web-01', 'web-02', 'db-01']

print(servers[0])

servers[0] = 'web-03'

Lists are heavily used for storing groups of resources such as servers, ports, buckets, or security groups.

ports = [22, 80, 443, 8080]

Tuple

Tuples are ordered and immutable.

aws_regions = (
    'us-east-1',
    'ap-south-1',
    'eu-west-1'
)

Attempting to modify a tuple results in an error.

aws_regions[0] = 'us-west-2'

This makes tuples useful for constants that should never change.

Set

Sets automatically remove duplicates.

unique_ips = {1, 2, 3, 3, 2, 1}

print(unique_ips)

Output:

{1, 2, 3}

A practical DevOps example:

raw_logs = {
    '10.0.0.1',
    '10.0.0.2',
    '10.0.0.1',
    '10.0.0.3'
}

Sets are excellent for deduplicating IP addresses and resource identifiers.

Dictionary

Dictionaries store key-value pairs and are arguably the most important data structure for cloud engineers.

instance = {
    'instance_id': 'i-0abc123',
    'type': 't2.micro',
    'region': 'ap-south-1',
    'status': 'running'
}

Accessing values:

print(instance['status'])

One key reason dictionaries matter:

AWS API responses, JSON payloads, Kubernetes objects, and Terraform outputs all map naturally to dictionaries.

Example:

ec2_instance = {
    'InstanceId': 'i-0abc123def456',
    'InstanceType': 't3.micro',
    'State': {'Name': 'running'},
    'PublicIpAddress': '13.234.56.78'
}

print(
    ec2_instance['State']['Name']
)


Typecasting

Typecasting converts one data type into another.

This becomes necessary because user input, environment variables, and many API values arrive as strings.

int('10')
float('10.5')
str(8080)

A common mistake:

int('10.5')

This raises:

ValueError

The correct approach:

int(float('10.5'))

Another important behavior:

int(38.99)

returns:

38

because int() truncates rather than rounds.


Boolean Truthiness

Python automatically evaluates values as either truthy or falsy.

Falsy values include:

0
0.0
''
None
[]
{}
()
set()

Examples:

bool(0)
# False

bool('')
# False

bool(' ')
# True

bool(None)
# False

A space character is not an empty string, which is why it evaluates to True.


Understanding eval()

The eval() function evaluates a string as Python code.

eval('1837')
eval('1837.63')
eval('True')

One benefit is automatic type detection.

x = eval(input())

However, using eval() with user input is dangerous.

eval(input())

can potentially execute arbitrary code.

For production automation scripts, explicit casting is always safer.

int()
float()


Input and Output

One of the most important beginner lessons:

input() always returns a string.

port = input("Enter port: ")

print(type(port))

Output:

<class 'str'>

Therefore:

port = int(
    input("Enter port: ")
)

is often required.

Python's print() function also supports formatting options:

print(
    "Python",
    "DevOps",
    "AWS",
    sep=" | "
)

print(
    "Building",
    end=" --> "
)


String Formatting

Python supports multiple formatting styles.

String concatenation:

'Server is in ' + name

Using .format():

'Server is in {}'.format(name)

Using f-strings:

f'Server is in {name}'

F-strings are the preferred modern approach.

service = "nginx"
status_code = 200

print(
    f"[INFO] {service} | Status: {status_code}"
)


DevOps Takeaway

The biggest insight from today's class was understanding that Python data structures are the language through which cloud services communicate.

An AWS API response is a dictionary.

A list of instances is a list.

A collection of unique IP addresses is a set.

Configuration constants fit naturally into tuples.

Environment variables arrive as strings and often require typecasting.

These concepts may seem simple initially, but they form the foundation of every automation script, cloud SDK interaction, and infrastructure workflow you'll build as a DevOps engineer.