day13-Python  installtion and datatypes

day13-Python installtion and datatypes

🔹What is Python?

Python is a high-level, interpreted, and general-purpose programming language that was first released in 1991 by Guido van Rossum. It is known for its simplicity, readability, and ease of use, making it an ideal choice for beginners as well as experienced developers. Python's design philosophy emphasizes code readability and a minimalist syntax, which allows programmers to express their ideas in fewer lines of code compared to other programming languages.

Key features of Python include:

  1. Readability: Python's syntax is clean and straightforward, making it easy to read and write code. It uses indentation to define code blocks, which enhances code readability.

  2. Dynamically Typed: Python is dynamically typed, which means you don't need to declare the data type of a variable explicitly. The type of a variable is determined during runtime.

  3. Interpreted Language: Python code is executed line by line, and it doesn't need to be compiled before execution, unlike languages like C++ or Java.

  4. Versatile and Expressive: Python supports a wide range of programming paradigms, including procedural, object-oriented, and functional programming styles. It offers many built-in data structures and libraries for various tasks.

  5. Extensive Libraries: Python has a rich standard library that provides tools for tasks such as working with text, networking, web development, data processing, and more. Additionally, there are numerous third-party libraries available through the Python Package Index (PyPI).

  6. High-Level Language: Python abstracts low-level details, making it easy for programmers to focus on problem-solving rather than managing memory or system resources.

Python is widely used for web development, data analysis, artificial intelligence, machine learning, scientific computing, automation, and scripting. Its versatility, large community support, and ease of learning have contributed to its popularity in various industries and domains.

🔹How to Install Python?

Ubuntu:

you can install Python using the package manager. For Python 3, use:

sudo apt update
sudo apt install python3

To check the version, open a terminal and type:

python3 --version

CentOS:

you can install Python using the package manager. For Python 3, use:

sudo yum update
sudo yum install python3

To check the version, open a terminal and type:

python3 --version

macOS:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install python3

To check the version, open a terminal and type:

python3 --version

Windows:

you can install Python:

https://www.python.org/downloads/

🔹Python Datatypes

Primitive Data Types:

Primitive data types are basic or fundamental data types built into the programming language. They represent single values and are not composed of other data types. In Python, the common primitive data types are:

  1. Integer (int): Represents whole numbers, both positive and negative, without any fractional part. Example: 5, -10, 100.

  2. Float (float): Represents numbers with a fractional part. Example: 3.14, -2.5, 0.75.

  3. Boolean (bool): Represents a binary value, either True or False. It is used for logical operations and control flow. Example: True, False.

  4. Character (char): Represents a single character enclosed in single quotes. However, Python doesn't have a distinct character data type; characters are represented as strings of length 1. Example: 'A', 'b', '1'.

Non-Primitive (Composite) Data Types:

Non-primitive data types are more complex data types created by combining multiple primitive or non-primitive data types. They can represent collections of values or objects. In Python, the common non-primitive data types are:

  1. String (str): Represents a sequence of characters. It is enclosed in single or double quotes. Example: "Hello", 'Python'.

  2. List (list): Represents an ordered collection of elements. It can store elements of different data types and is mutable (can be changed after creation). Example: [1, 'apple', True].

  3. Tuple (tuple): Similar to lists, but enclosed in parentheses. Tuples are immutable (cannot be changed after creation). Example: (1, 'apple', True).

  4. Dictionary (dict): Represents a collection of key-value pairs enclosed in curly braces {}. Keys must be unique and immutable, while values can be of any data type. Example: {'name': 'John', 'age': 30}.

  5. Set (set): Represents an unordered collection of unique elements enclosed in curly braces {}. Duplicates are automatically removed. Example: {1, 2, 3}.

  6. Frozenset (frozenset): Similar to sets, but immutable. Example: frozenset({1, 2, 3}).

  7. Range (range): Represents a sequence of numbers. It is commonly used in loops. Example: range(1, 5).

  8. Bytes (bytes): Represents a sequence of bytes. It is used for handling binary data. Example: b'Hello'.

  9. Bytearray (bytearray): Similar to bytes, but mutable. Example: bytearray(b'Hello').

  10. Complex (complex): Represents a complex number in the form of a + bj, where a and b are real numbers, and j represents the square root of -1. Example: 3 + 4j.

These data types are the building blocks for storing and manipulating data in Python programs. Understanding them is essential for writing efficient and effective code.