Python for DevOps – Day 38: Introduction to Python Essentials
Welcome back to Day 38 of our Python for DevOps journey! Today, we're diving into the core building blocks of Python — crucial for writing scripts, managing automation, and working with infrastructure-as-code tools.
Whether you're writing a quick script to automate deployments or building complex CI/CD pipelines, understanding Python's basics makes you a more powerful and efficient DevOps engineer.
Let’s cover:
🧠 1. Variables
Variables are containers for storing data values. In Python, you don’t need to declare a type — just assign and go.
Question1:Create two variables: one for your name and one for your age. Print them.
📦 2. Data Types
Python has dynamic typing, which means types are inferred automatically. Some common data types:
Question2:Create variables of different data types: int, float, string, bool, and print their type using type().
🧩 3. Keywords
Keywords are reserved words that have a special meaning in Python and cannot be used as variable names.
Examples:
if, else, for, while, def, return, import, True, False, None
Try this to list all keywords:
import keyword print(keyword.kwlist)
Question 3:List all Python keywords using a built-in module.
➕ 4. Operators
Operators are used to perform operations on variables and values.
Example:
a = 10 b = 5 print(a + b) # Output: 15
Question 4:Create two numbers and perform arithmetic, comparison, and logical operations on them.
💬 5. Comments
Comments are used to explain the code and make it readable.
# This is a comment
""" This is a multi-line comment """
Question 6:Write a program with both single-line and multi-line comments explaining what it does.
Insightful