Python Basics β€” `print()`, Variables, Identifiers, Data Types

Published: (June 11, 2026 at 01:01 PM EDT)
6 min read
Source: Dev.to

Source: Dev.to

πŸ“Œ 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

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)) #

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)

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

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)

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.

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

βœ… 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. 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’]

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

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}”)

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

β€œIs Python statically or dynamically typed?” type() to check.

β€œWhat’s the difference between = and == in Python?” = assigns a value. == compares two values. Critical distinction in if conditions.

β€œWhat is id() used for?”

β€œCan a variable name start with a number?” _.

β€œWhat happens if you name a variable list or print?”

β€œWhat is dynamic typing and why does it matter in DevOps scripts?” str by 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!

Write a Python script that stores your name, age, and city in variables and prints them with their data types. Try assigning if = 10 and run it. What error do you get? Now look up keyword.kwlist and list 5 keywords you didn’t know. What is the output of this code? Explain why:

a = β€œ8080” print(a, type(a))

Create variables for: EC2 instance type, region, number of replicas, and whether auto-scaling is enabled. Print each with its type. Now reassign replicas from int to a str β€” what changes? Write a script that takes a server name as input and prints: β€œConnecting to: ”. What type does input() always return? Explain with code why print = 100 breaks things and how you would fix it without restarting Python. 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 change port from int to str (e.g., from 8080 to β€œ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: | Type: ”. Add a comment explaining why you’d never name this variable input or print. Python for DevOps & Cloud*

0 views
Back to Blog

Related posts

Read more Β»

The spec is in the wrong place

My day job is at a large tech company. Hundreds of engineering teams, and every one of them is somewhere different on AI adoption. Some are still treating codin...

The Heuristics Say Don't

A culture that only records its disasters ends up with a biased archive. Wars documented, plagues chronicled, collapses catalogued. The quiet decades go unwritt...