๐ Key Concepts
| Concept | One-Line Definition |
|---|---|
print() |
Built-in function to output data to the terminal |
| Variable | A named container in memory that holds a value |
| Dynamic Typing | Python figures out the data type automatically at runtime |
| Identifier | The name you give to a variable, function, or class |
| Keyword | Reserved words Python uses internally โ cannot be used as identifiers |
type() |
Built-in function that tells you the data type of a value |
id() |
Returns the memory address of an object |
๐ค Syntax
# print() โ basic output
print("Hello DevOps")
print(variable_name)
print(value, type(value)) # print value AND its type together
# Variable assignment
port = 8080 # int
service_name = "nginx" # str
cpu_threshold = 85.5 # float
# type() โ check data type
print(type(port)) # <class 'int'>
# id() โ check memory address
print(id(service_name))
# keyword list
import keyword
print(keyword.kwlist)
# input() โ take user input
name = input("Enter your name: ")
print("Hello", name)
๐ Core Concepts Explained
1. print() Function
The most basic output function. In DevOps scripts, you'll use it constantly to log statuses, debug values, and show results.
print("Deployment started")
print("Server IP:", server_ip)
print("Status:", status, "| Code:", code) # multiple values with comma
2. Variables
A variable is just a label pointing to a value in memory. Think of it like naming a config value so you can reuse it.
# BAD โ hardcoded everywhere
# connect("192.168.1.10", 22)
# connect("192.168.1.10", 22)
# GOOD โ use a variable
server_ip = "192.168.1.10"
ssh_port = 22
connect(server_ip, ssh_port)
3. Dynamic Typing
Python doesn't require you to declare the type. It detects it automatically. The same variable can hold different types at different times.
a = 10 # int
a = "hello" # now str โ Python is fine with this
a = 3.14 # now float
โ ๏ธ Common Mistake: Reassigning a variable to a different type accidentally can cause bugs in automation scripts.
4. Data Types (from class)
| Type | Example | DevOps Use Case |
|---|---|---|
int |
port = 22 |
Port numbers, exit codes |
float |
cpu = 85.5 |
CPU/memory thresholds |
str |
env = "prod" |
Environment names, server IPs |
bool |
is_healthy = True |
Health check flags |
port = 22 # int
threshold = 85.5 # float
environment = "prod" # str
is_active = True # bool
5. Identifiers โ Naming Rules
โ
VALID โ INVALID
server_ip 5server (starts with number)
_private server-ip (hyphen = minus operator)
cpu2core server ip (space not allowed)
myVar if (reserved keyword)
EC2Instance print = 100 (shadows built-in โ avoid!)
Golden Rule for DevOps Scripts: Use snake_case (lowercase with underscores) โ server_ip, max_retries, aws_region. This matches Python convention and is easy to read.
6. Keywords โ Off-Limits Names
import keyword
print(keyword.kwlist)
# ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',
# 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
# 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
# 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return',
# 'try', 'while', 'with', 'yield']
7. Don't Shadow Built-ins โ ๏ธ
The class demonstrated this critical mistake:
# โ NEVER do this
print = 100 # You just killed the print function!
print("Python") # TypeError: 'int' object is not callable
# โ
Restart kernel or use del to recover
del print
print("Python") # Works again
Common built-ins to never overwrite: print, input, list, dict, str, int, len, open, type, id
โ๏ธ DevOps / Cloud Use Cases
# AWS EC2 config variables
instance_type = "t2.micro"
region = "ap-south-1" # Mumbai
ami_id = "ami-0abcdef1234567890"
max_instances = 5
spot_price = 0.012 # float โ price in USD
# Docker/K8s config
container_port = 8080
replica_count = 3
image_tag = "nginx:1.25"
is_rolling_update = True
# CI/CD pipeline variable
build_status = "SUCCESS"
exit_code = 0 # 0 = success in Linux/bash
artifact_size_mb = 145.7
# Log line output (you'll do this in every script)
print(f"Deploying {image_tag} to {region} with {replica_count} replicas")
print(f"Build: {build_status} | Exit Code: {exit_code}")
โ Common Mistakes (from class + real world)
| Mistake | Example | Fix |
|---|---|---|
| Typo in function name | prin("Python") |
Check spelling โ Python gives NameError
|
| Shadow a built-in | print = 100 |
Never use built-in names as variables |
| Use keywords as names | if = 5 |
Use keyword.kwlist to check |
| Start var with number | 5server = "aws" |
Start with letter or underscore |
| Space in variable name | server ip = "x" |
Use server_ip
|
| Wrong case | Print("hi") |
Python is case-sensitive โ print โ Print
|
๐ฏ Interview Points
"Is Python statically or dynamically typed?"
โ Dynamically typed. Types are determined at runtime, not declared. Usetype()to check."What's the difference between
=and==in Python?"
โ=assigns a value.==compares two values. Critical distinction inifconditions."What is
id()used for?"
โ Returns memory address. Useful to understand if two variables point to the same object in memory."Can a variable name start with a number?"
โ No. It can start with a letter (A-Z, a-z) or underscore_."What happens if you name a variable
listorprint?"
โ You shadow the built-in. The original function becomes inaccessible in that scope โ a common bug."What is dynamic typing and why does it matter in DevOps scripts?"
โ Python auto-detects types, so you must be careful when reading user input or config values โ they come in asstrby default, even if they look like numbers.
๐ Knowledge Base (Quick Revision)
# โโ PRINT โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
print("text") # basic
print(var, type(var)) # value + type
print("Label:", value) # label + value
# โโ VARIABLES & TYPES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
x = 10 # int
x = 3.14 # float
x = "hello" # str
x = True # bool
# โโ USEFUL BUILT-INS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
type(x) # what type is x?
id(x) # memory address of x
input("Enter: ") # get user input (returns str)
# โโ KEYWORDS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import keyword
keyword.kwlist # list of all reserved words
# โโ IDENTIFIER RULES โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ
letters, digits (not first), underscore
# โ spaces, hyphens, special chars, keywords, starts with digit
# โโ BUILT-IN SAFETY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
dir(__builtins__) # list ALL built-in names
# Never use these as variable names!
๐๏ธ Practice Questions
Easy
- Write a Python script that stores your name, age, and city in variables and prints them with their data types.
- Try assigning
if = 10and run it. What error do you get? Now look upkeyword.kwlistand list 5 keywords you didn't know. - What is the output of this code? Explain why:
a = "8080"
print(a, type(a))
Medium
- Create variables for: EC2 instance type, region, number of replicas, and whether auto-scaling is enabled. Print each with its type. Now reassign
replicasfromintto astrโ what changes? - Write a script that takes a server name as input and prints:
"Connecting to: <server_name>". What type doesinput()always return? - Explain with code why
print = 100breaks things and how you would fix it without restarting Python.
DevOps-Focused
-
Config Validator Script: Write a script that stores 5 deployment config values (instance type, port, region, replica count, environment name). Print each value, its type, and its memory
id. Then changeportfrominttostr(e.g., from8080to"8080") and explain the real-world implication in a comment. -
Build Status Logger: Write a script that uses
input()to ask for a build status (SUCCESS/FAILED), stores it in a variable, and prints:"Pipeline result: <status> | Type: <type>". Add a comment explaining why you'd never name this variableinputorprint.
Python for DevOps & Cloud*
Top comments (6)
This is a fantastic beginner-friendly breakdown of Python essentials for DevOps and cloud workflows. I really appreciate how you tie core conceptsโlike print(), variables, dynamic typing, and identifiersโto real-world DevOps use cases, such as managing AWS instances, Docker/Kubernetes configuration, and CI/CD pipelines.
Your emphasis on avoiding shadowing built-ins, respecting keywords, and using snake_case for clarity is especially important for beginners who are learning best practices early.
Iโd love to collaborate or exchange exercisesโperhaps we could create a series of guided Python challenges specifically tailored to DevOps and cloud automation, building from basics to more advanced tasks like configuration validation and deployment logging. This could be a great way to help beginners bridge theory and practical application.
Would you be open to discussing that further?
Thank you for the thoughtful feedback! Iโm glad you found the DevOps and cloud examples useful. My goal with these posts is to build strong Python fundamentals while continuously connecting them to real-world automation, infrastructure, and cloud engineering use cases.
I really like your idea of DevOps-focused Python challenges. As I progress into topics like file handling, APIs, automation scripts, logging, and cloud integrations, I can see how structured exercises would help bridge the gap between learning concepts and applying them in practice.
I'm always happy to connect with people who are learning, teaching, or working in this space. Feel free to connect with me, and I'd be interested in following your work and exchanging ideas as I continue this learning journey.
Thanks again for the encouragement and the great suggestion!
Thank you! I'm documenting my journey from scratch for proof of work and for others too who like concepts simplified.
Sure, we can discuss.
Welcome.
You can confirm my portfolio on my profile.
I will wait for your response.
Best regards.
Clean and beginner-friendly breakdown! These fundamentals are exactly where most Indian CS students struggle before jumping into AI/ML. Keep writing โ this kind of content genuinely helps freshers.
Thank you. It's always better to make concepts crisp and short and replacing the reading time to actually implementing which makes it more clear to understand.