Day 13 Basics of Python

Day 13  Basics of Python

What is Python?

Python is a high-level, general-purpose, and interpreted programming language used in various sectors including machine learning, artificial intelligence, data analysis, web development, and many more. Python is known for its ease of use, powerful standard library, and dynamic semantics. It also has a large community of developers who keep on contributing towards its growth. The major focus behind creating it is making it easier for developers to read and understand, also reducing the lines of code

History of Python:-

It was created by Guido van Rossum and first released in 1991. Here's a brief history of Python:

  1. Origin: Guido van Rossum began working on Python in the late 1980s at the Centrum Wiskunde & Informatica (CWI) in the Netherlands. He wanted to create a language that was easy to learn and use, yet powerful and versatile.

  2. First Release (1991): Python 0.9.0 was released in February 1991. It included features like exception handling, functions, and modules.

  3. Python 1.0 (1994): The first official version, Python 1.0, was released in January 1994. This version included many of the features that are still present in Python today, such as lambda, map, filter, and reduce functions.

  4. Python 2.x: The 2.x series, starting with Python 2.0 in 2000, brought significant improvements and enhancements to the language. Python 2.0 introduced features like garbage collection and Unicode support.

  5. Python 3.x: Python 3.0, also known as "Python 3000" or "Py3k," was released in December 2008. It was a major revision of the language that is not entirely backward-compatible with Python 2.x. Python 3.x aimed to clean up and simplify the language, removing inconsistencies and improving Unicode support.

  6. Recent Releases: Python continues to evolve, with regular releases bringing new features, improvements, and optimizations. The Python Software Foundation (PSF) oversees the development and maintenance of the language.

  7. Popularity and Adoption: Python has seen widespread adoption in various fields, including web development, data science, artificial intelligence, scientific computing, and education. Its simplicity and versatility have contributed to its popularity among developers.

  8. Community: Python has a vibrant and active community of developers who contribute to its ecosystem by creating libraries, frameworks, and tools. The Python Package Index (PyPI) hosts thousands of packages that extend Python's functionality for different purposes.

  9. Philosophy: Python has a philosophy emphasizing readability, simplicity, and explicitness, which is encapsulated in "The Zen of Python," a set of aphorisms accessible via the import this command in Python.

How to Install Python?

Installing Python is straightforward, and there are several methods available depending on your operating system. Here's how to install Python on some common platforms:

Installing Python on Windows:

  1. Download Python Installer:

    • Go to the official Python website: python.org.

    • Click on the "Downloads" tab.

    • Choose the latest version of Python for Windows and download the installer (either the 32-bit or 64-bit installer, depending on your system).

  2. Run Installer:

    • Once the installer is downloaded, double-click on it to launch.

    • Check the box that says "Add Python x.x to PATH" during the installation process. This will add Python to your system PATH, allowing you to run Python from the command line easily.

    • Click "Install Now" to begin the installation process.

  3. Verify Installation:

    • Open Command Prompt (search for "cmd" in the Start menu).

    • Type python --version and press Enter. You should see the installed Python version.

Installing Python on macOS:

  1. Install Homebrew (Optional):

    • If you don't have Homebrew installed, you can install it by following the instructions on the Homebrew website: brew.sh.
  2. Install Python:

    • Open Terminal (you can find it in Applications/Utilities or search for it in Spotlight).

    • Type the following command and press Enter:

        brew install python
      
  3. Verify Installation:

    • In Terminal, type python3 --version and press Enter. You should see the installed Python version.

Installing Python on Linux:

  1. Using Package Manager:

    • Most Linux distributions come with Python pre-installed. You can use the package manager specific to your distribution to install Python.

    • For example, on Ubuntu or Debian-based systems, you can use apt:

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

    • Open a terminal and type python3 --version to verify that Python is installed and to see the installed version.

Task 1 :-

1.Read about different Data Type in Python

Python supports several built-in data types that are fundamental to programming. Here are the main data types in Python:

  1. Numeric Types:

    • int: Integers, which are whole numbers with no decimal point, e.g., 5, -10, 100.

    • float: Floating-point numbers, which are numbers with a decimal point or numbers written in scientific notation, e.g., 3.14, -0.001, 2.5e3.

  2. Boolean Type:

    • bool: Boolean values representing truth values, either True or False.
  3. Sequence Types:

    • str: Strings, which represent sequences of characters enclosed in single (' ') or double (" ") quotes, e.g., "hello", 'world'.

    • list: Lists, which are ordered collections of items that can be of different types, enclosed in square brackets [], e.g., [1, 2, 3], ['a', 'b', 'c'].

    • tuple: Tuples, similar to lists but immutable (cannot be changed after creation), enclosed in parentheses (), e.g., (1, 2, 3), ('x', 'y', 'z').

  4. Mapping Type:

    • dict: Dictionaries, which are unordered collections of key-value pairs enclosed in curly braces {}, e.g., {'name': 'John', 'age': 30}, {1: 'one', 2: 'two'}.
  5. Set Types:

    • set: Sets, unordered collections of unique elements enclosed in curly braces {}, e.g., {1, 2, 3}, {'a', 'b', 'c'}.

    • frozenset: Immutable sets, similar to sets but cannot be changed after creation.

  6. None Type:

    • NoneType: Represents the absence of a value or a null value, denoted by the keyword None.

These are the main built-in data types in Python. Additionally, Python provides support for complex numbers (complex type), as well as other data types through modules and libraries (e.g., arrays, data frames, etc., via libraries like NumPy and Pandas). Understanding and working with these data types are essential for writing Python programs effectively.