Day 13 Introduction to Python

Day 13 Introduction to Python

Python, has gained immense popularity for its simplicity, versatility, and readability. Whether you're a seasoned developer or just embarking on your coding journey, Python serves as an excellent choice due to its wide range of applications, from web development and data analysis to artificial intelligence and automation.

What is Python?

Python is a high-level, interpreted programming language known for its clean syntax and easy-to-understand code structure. Created by Guido van Rossum and first released in 1991, Python emphasizes code readability, making it accessible even to beginners. Its versatility allows developers to write code efficiently and effectively for various domains.

One of the key features of Python is its extensive standard library, which provides support for numerous tasks without requiring additional installations. Additionally, Python's vibrant community continually contributes to its ecosystem by developing third-party libraries and frameworks, expanding its capabilities further.

How to install Python?

You can install Python in your System whether it is window, MacOS, ubuntu, centos etc.

Task:

  1. Install Python in your respective OS, and check the version.

Go to Python.org and download the latest version for your OS preferances. Download Visual Studio Code on your machine. Open VSCode and create a new folder for your project. Navigate to the new folder and select new terminal from dropdown list.

Write below command to install python on Windows:

pip install virtualenv

For every project we need to create virtual environment, A virtual environment in Python is a self-contained directory that encapsulates a specific Python interpreter along with its dependencies. It allows developers to create isolated environments for different projects, each with its own set of libraries and dependencies, without interfering with the system-wide Python installation or other projects.

virtualenv -p python3.12 env

env folder gets created here after running the above command, We will navigate it to the Project folder that we want to create.

Now we will activate the environment here using script activate.bat

Now we will check the Version inside virtual environment as well as through windows cmd.

Installation of python on Linux

sudo apt update
sudo install python3
python3 --version

  1. Understanding Data Types in Python

In Python, data types categorize the kinds of values that variables can hold. Understanding these data types is crucial for writing efficient and bug-free code. Python offers several built-in data types, each serving different purposes. Let's explore some of the fundamental data types in Python:

  1. Numeric Types:

    • int: Represents whole numbers without any decimal point. For example, 5, -10, and 1000.

    • float: Represents numbers with a decimal point or in exponential form. For example, 3.14, 2.718, and 1.0e-5.

    • complex: Represents complex numbers in the form a + bj, where a and b are floats and j represents the imaginary unit. For example, 2 + 3j, 1.5 - 2.5j.

  2. Sequence Types:

    • str: Represents a sequence of characters enclosed within single, double, or triple quotes. For example, 'Hello', "Python", and '''World'''.

    • list: Represents an ordered collection of items enclosed within square brackets and separated by commas. Lists are mutable, meaning their elements can be changed after creation. For example, [1, 2, 3], ['apple', 'banana', 'orange'].

    • tuple: Similar to lists but immutable, meaning their elements cannot be changed after creation. Tuples are enclosed within parentheses. For example, (1, 2, 3), ('apple', 'banana', 'orange').

  3. Mapping Type:

    • dict: Represents a collection of key-value pairs enclosed within curly braces. Each key is unique, and its associated value can be of any data type. For example, {'name': 'John', 'age': 30, 'city': 'New York'}.
  4. Set Types:

    • set: Represents an unordered collection of unique items. Sets are enclosed within curly braces and can contain items of different data types. For example, {1, 2, 3}, {'apple', 'banana', 'orange'}.
  5. Boolean Type:

    • bool: Represents a Boolean value, which can be either True or False. Booleans are often used for logical operations and control flow in Python.

Understanding and effectively utilizing these data types empower Python developers to write efficient and robust code, capable of handling diverse computational tasks.

Thanks for reading...!!!

Happy Learning....!!!!