Skip to main content

Command Palette

Search for a command to run...

The Basics of Python

Published
3 min readView as Markdown
The Basics of Python
N

I am a highly motivated and enthusiastic individual completed B.Tech from Savitribai Phule University, Pune . With a strong interest in DevOps and Cloud technologies, I am eager to kick-start my career in this domain. Although I do not have much professional experience, I possess a willingness to learn, excellent problem-solving skills, and a passion for technology. I am committed to contributing my best to any team I work with.

Welcome to Day 13 of the #90DaysOfDevOps challenge. Today, we will dive into the fundamentals of Python, a versatile programming language widely used by DevOps engineers to build logic and programs. Whether you're a beginner or have some experience with Python, this article will provide you with a solid foundation to enhance your skills.

What is Python?

Python is an open-source, general-purpose, high-level, and object-oriented programming language. It was created by Guido van Rossum and has gained popularity among DevOps engineers due to its versatility and extensive ecosystem of libraries and frameworks. Python provides powerful tools for automating tasks, managing infrastructure, and working with cloud platforms.

Task 1 - How to Install Python on macOS and Ubuntu

macOS Installation:

  1. Open a web browser and navigate to the official Python website at https://www.python.org.

  2. Click on the "Downloads" tab and select the latest version of Python suitable for macOS.

  3. Download the macOS installer package (a .pkg file).

  4. Double-click the downloaded file to start the installation wizard.

  5. Follow the on-screen instructions, selecting the appropriate options as you go.

  6. Once the installation is complete, open a terminal and run the command python3 --version to verify the installation and display the installed Python version.

Ubuntu Installation:

  1. Open a terminal on your Ubuntu system.

  2. Run the following command to update the package lists: sudo apt update

  3. Next, install Python 3 by running the command: sudo apt install python3

  4. After the installation is complete, verify the installation by running the command python3 --version in the terminal. This will display the installed Python version.

By following these installation steps, you will have Python up and running on your macOS or Ubuntu system.

Task 2 - Exploring Different Data Types in Python

Python is a versatile programming language that supports various data types. Understanding these data types is crucial for writing effective and efficient code. Let's have a closer look at some of the commonly used data types in Python:

1. Numeric Data Types

Python provides two main numeric data types:

  • Integers: Represent whole numbers, such as 1, -5, or 1000. They can be declared using the int keyword. Example: age = 25

  • Floating-Point Numbers: Represent decimal numbers, such as 3.14 or -0.5. They can be declared using the float keyword. Example: pi = 3.14159

2. String Data Type

Strings in Python are sequences of characters enclosed in single ('') or double quotes (""). They allow you to work with textual data and manipulate strings using various built-in methods. Example: name = "John Doe"

3. List Data Type

Lists are ordered collections of items enclosed in square brackets ([]). They can store elements of different data types and provide flexibility in adding, removing, and accessing items. Example: numbers = [1, 2, 3, 4, 5]

4. Tuple Data Type

Similar to lists, tuples are ordered collections of items. However, tuples are immutable, meaning they cannot be modified once created. They are defined using parentheses (()). Example: coordinates = (10, 20)

5. Dictionary Data Type

Dictionaries are key-value pairs enclosed in curly braces ({}). They allow you to store and retrieve values based on unique keys. Dictionaries are useful for representing real-world objects and mapping relationships between entities. Example: person = {"name": "John", "age": 25, "city": "London"}

6. Boolean Data Type

Booleans represent either True or False. They are commonly used in conditional statements and logical operations to control the flow of a program. Example: is_valid = True

Python also provides additional data types such as sets, byte arrays, and more, which have specific use cases and functionalities. Example of set: fruits = {"apple", "banana", "orange"}

More from this blog

Nikhil Yadav's blog

65 posts