Python for DevOps – Day 38: Introduction to Python Essentials

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.


Article content

📦 2. Data Types

Python has dynamic typing, which means types are inferred automatically. Some common data types:

  • int: integers → age = 30
  • float: decimals → pi = 3.14
  • str: strings → msg = "Hello DevOps"
  • bool: boolean → is_active = True
  • list, tuple, dict, set: collection types

Question2:Create variables of different data types: int, float, string, bool, and print their type using type().


Article content

🧩 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.


Article content

➕ 4. Operators

Operators are used to perform operations on variables and values.

  • Arithmetic: + - * / % // **
  • Assignment: = += -= *= /=
  • Comparison: == != > < >= <=
  • Logical: and or not
  • Bitwise, Identity, Membership — also useful in advanced scripting.

Example:

a = 10 b = 5 print(a + b) # Output: 15

Question 4:Create two numbers and perform arithmetic, comparison, and logical operations on them.


Article content

💬 5. Comments

Comments are used to explain the code and make it readable.

  • Single-line comment:

# This is a comment

  • Multi-line comment:

""" This is a multi-line comment """

Question 6:Write a program with both single-line and multi-line comments explaining what it does.


Article content


To view or add a comment, sign in

More articles by Vijesh Verma

Explore content categories