Day 15 Task: Basics of Python for DevOps Engineers

Getting Started with Python: Installation and Data Types

Welcome to the exciting world of Python programming! In this guide, we will walk you through the steps to install Python on your operating system and explore its fundamental data types. Whether you're a beginner or refreshing your knowledge, this guide is tailored for you.


Step 1: Installing Python

Windows Installation

  1. Download Python:

  2. Install Python:

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

    • Follow the on-screen instructions to complete the installation.

  3. Verify Installation:

    • Open Command Prompt (cmd) and type:

        python --version
      
    • Press Enter to check the installed Python version.


macOS Installation

  1. Download Python:

  2. Install Python:

    • Open the downloaded file and follow the instructions to install Python.
  3. Verify Installation:

    • Open Terminal and type:

        python3 --version
      

Linux Installation

  1. Check if Python is Installed:

    • Open Terminal and type:

        python3 --version
      
    • If Python is already installed, it will display the version.

  2. Install Python (If Not Installed):

    • For Ubuntu and Debian-based distributions, use:

        sudo apt update
        sudo apt install python3
      
  3. Verify Installation:

    • After installation, confirm Python is installed by running:

        python3 --version
      

Step 2: Understanding Data Types in Python

Once Python is installed, it's time to explore its core components—data types. Python provides a variety of built-in data types that help store and manipulate data efficiently.

1. Numeric Types

  • int: Represents whole numbers.

      a = 10  # Integer
    
  • float: Represents decimal numbers.

      b = 10.5  # Float
    
  • complex: Represents numbers with real and imaginary parts.

      c = 3 + 4j  # Complex number
    

2. Sequence Types

  • str: Represents text (strings).

      name = "Alice"  # String
    
  • list: An ordered, mutable collection of elements.

      numbers = [1, 2, 3, 4, 5]  # List
    
  • tuple: An ordered, immutable collection of elements.

      coordinates = (10.0, 20.0)  # Tuple
    

3. Mapping Type

  • dict: A collection of key-value pairs.

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

4. Set Types

  • set: An unordered collection of unique elements.

      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 successfully installing Python and exploring its fundamental data types! Understanding these data types is essential for efficient programming and data manipulation in Python.

As you continue your Python journey, experiment with these data types by writing your own examples and testing their functionalities. Stay curious and happy coding! 🚀

0
Subscribe to my newsletter

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

Written by

Shubhranshu Ransingh
Shubhranshu Ransingh