Basics of Python for DevOps Engineers

Ammar KhanAmmar Khan
3 min read

Getting Started with Python: Installation and Data Types

Welcome to the exciting world of Python programming! In this blog post, we will walk you through the steps to install Python on your operating system and explore the various data types available in Python. Whether you're a beginner or brushing up on your skills, this guide is designed for you.

Step 1: Installing Python

Windows

  1. Download Python:

  2. Install Python:

    • Run the installer and ensure you check the box that says “Add Python to PATH” to easily access Python from the command line.

    • Follow the installation instructions.

  3. Check Python Version:

    • Open the Command Prompt (cmd).

    • Type the following command and press Enter:

 python --version

macOS

  1. Download Python:

  2. Install Python:

    • Open the downloaded file and follow the instructions to install Python.
  3. Check Python Version:

    • Open the Terminal.

    • Type the following command and press Enter:

  python3 --version

Linux

  1. Install Python:

    • Most Linux distributions come with Python pre-installed. You can check if it’s installed by opening the terminal and typing:
  python3 --version

If Python is not installed, you can install it using the package manager. For example, on Ubuntu, run:

  sudo apt update
  sudo apt install python3

Check Python Version:

In the terminal, type:

  •      python3 --version
    

Step 2: Understanding Data Types in Python

Once you have Python installed, it's time to delve into its core components—data types. Python offers a rich set of built-in data types, which can be categorized as follows:

1. Numeric Types

int: Represents whole number

a = 10  # Integer

float: Represents decimal numbers.

 b = 10.5  # Float

2. Sequence Types

str: Represents strings (text).

name = "Alice"  # String

list: An ordered and mutable collection of items.

numbers = [1, 2, 3, 4, 5]  # List

tuple: An ordered and immutable collection of items.

coordinates = (10.0, 20.0)  # Tuple

3. Mapping Type

dict: A collection of key-value pairs that is unordered.

person = {"name": "Bob", "age": 25}  # Dictionary

4. Set Types

set: An unordered collection of unique items.

unique_numbers = {1, 2, 3}  # Set

frozenset: An immutable version of a set.

frozen_set = frozenset([1, 2, 3])  # Frozenset

5. Boolean Type

bool: Represents True or False values.

is_active = True  # Boolean

Conclusion

Congratulations on installing Python and learning about its fundamental data types! Understanding these data types is crucial for effective programming in Python, as they form the backbone of any application you develop.

As you continue your journey with Python, explore these data types further by writing your own examples and experimenting with their functionalities. Happy coding!

0
Subscribe to my newsletter

Read articles from Ammar Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ammar Khan
Ammar Khan