1. What is Python?
Overview:
Python is an open-source, general-purpose, high-level, and object-oriented programming language.
It was created by Guido van Rossum and is known for its readability and simplicity.
Python has a rich ecosystem with vast libraries and frameworks, including:
Django - A high-level web framework.
Flask - A lightweight web framework.
TensorFlow - A library for machine learning.
Pandas - A data manipulation and analysis library.
Keras - A deep learning API.
2. How to Install Python?
Installation Instructions:
Windows:
Go to the official Python website.
Download the installer for your version.
Run the installer and ensure you check the box that says "Add Python to PATH."
Follow the installation steps.
Ubuntu: Open the terminal and run:
sudo apt-get update sudo apt-get install python3
macOS:
Open the terminal.
You can use Homebrew to install Python:
brew install python
CentOS: Open the terminal and run:
sudo yum install python3
3. Checking the Python Version
After installation, you can check the installed version of Python by running the following command in your terminal (or command prompt):
python3 --version
or
python --version
4. Read About Different Data Types in Python
In Python, the primary built-in data types include:
Numeric Types:
int: Integer numbers, e.g.,
5
,-3
.float: Floating-point numbers (decimals), e.g.,
3.14
,-0.001
.complex: Complex numbers, e.g.,
2 + 3j
.
Sequence Types:
str: String (text), e.g.,
"Hello, World!"
.list: Ordered, mutable collections of items, e.g.,
[1, 2, 3, "Python"]
.tuple: Ordered, immutable collections of items, e.g.,
(1, 2, 3)
.
Mapping Type:
- dict: Unordered collections of key-value pairs, e.g.,
{"name": "Alice", "age": 25}
.
- dict: Unordered collections of key-value pairs, e.g.,
Set Types:
set: Unordered collections of unique items, e.g.,
{1, 2, 3}
.frozenset: Immutable sets.
Boolean Type:
- bool: Represents
True
orFalse
.
- bool: Represents
Tasks
Task 1: Install Python and Check Version
Follow the installation steps for your respective operating system.
Run the command to check the version of Python installed.
Task 2: Explore Data Types
- Research each data type mentioned above and create examples in your Python environment.
Example Code Snippet:
You can also try out the following code snippet to see Python's data types in action:
# Numeric Types
a = 10 # int
b = 3.14 # float
c = 1 + 2j # complex
# Sequence Types
my_string = "Hello, Python!" # str
my_list = [1, 2, 3, "Hello"] # list
my_tuple = (1, 2, 3) # tuple
# Mapping Type
my_dict = {"name": "Fauzeya", "age": 25} # dict
# Set Types
my_set = {1, 2, 3} # set
my_frozenset = frozenset([1, 2, 3]) # frozenset
# Boolean Type
is_python_fun = True # bool
# Print data types
print(type(a), type(b), type(c))
print(type(my_string), type(my_list), type(my_tuple))
print(type(my_dict))
print(type(my_set), type(my_frozenset))
print(type(is_python_fun))
This code will print the data types of each variable, giving you a practical understanding of how they work in Python.