Skip to main content

Command Palette

Search for a command to run...

🐍 What is Python?

Published
4 min readView as Markdown

Python is one of the most powerful and easy-to-learn programming languages used today. Created by Guido van Rossum and released in 1991, Python has become the go-to language for developers, data scientists, and even beginners because of its simple syntax and versatility.

💡 Why Learn Python?

Python can be used for:

  • Web development – Frameworks like Django and Flask

  • Data Science & AI – Libraries like NumPy, Pandas, TensorFlow

  • Automation and scripting – Save time with automation tools

  • Game development – With libraries like Pygame

  • Software testing and DevOps

Python’s readability and community support make it an ideal first programming language.


🧩 Python Data Types Explained

Everything in Python is an object, and each object has a data type. Data types define the type of value stored in a variable and what operations can be performed on it.

Let’s look at the most common Python data types:

1. Numeric Types

Used for representing numbers.

TypeDescriptionExample
intInteger numbersx = 10
floatDecimal numbersy = 10.5
complexComplex numbers (real + imaginary)z = 2 + 3j

Example:

a = 5       # int
b = 3.2     # float
c = 1 + 2j  # complex

2. String (str)

Strings represent text enclosed in quotes.

name = "Python"
print(name)

3. Boolean (bool)

Boolean data types have only two possible values: True or False.

is_easy = True
print(is_easy)

4. List

An ordered, mutable (changeable) collection.

fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
print(fruits)

5. Tuple

Similar to lists, but immutable (cannot be changed).

coordinates = (10.5, 20.3)

6. Set

An unordered collection of unique items.

unique_numbers = {1, 2, 3, 3, 4}
print(unique_numbers)  # Output: {1, 2, 3, 4}

7. Dictionary (dict)

Stores data in key–value pairs.

student = {"name": "Alice", "age": 22, "course": "Python"}
print(student["name"])

🔄 Type Conversion in Python

Type conversion means changing one data type into another.
Python supports two main types of conversions:


1. Implicit Type Conversion (Type Coercion)

In this type, Python automatically converts one data type to another without the programmer’s intervention.

Example:

a = 5       # int
b = 2.5     # float
result = a + b
print(result)      # Output: 7.5
print(type(result))  # Output: <class 'float'>

Here, Python converts a (integer) into a float automatically.


2. Explicit Type Conversion (Type Casting)

In explicit conversion, the programmer manually changes the data type using built-in functions such as:

  • int()

  • float()

  • str()

  • list()

  • tuple()

  • set()

  • dict()

Example:

# Float to int
num = 10.8
int_num = int(num)
print(int_num)  # Output: 10

# String to int
s = "25"
num = int(s)
print(num + 5)  # Output: 30

# Int to string
age = 22
text = str(age)
print("I am " + text + " years old")  # Output: I am 22 years old

⚠️ Note: If you try to convert incompatible data (like int("Hello")), Python will raise a ValueError.


🧠 Summary Table

ConceptDescriptionExample
PythonA high-level, interpreted programming languageprint("Hello, World!")
Data TypesDefines the kind of data stored in variablesint, float, str, list, etc.
Explicit ConversionManually changing one data type to anotherint("10"), str(123)

❓ Frequently Asked Questions (FAQs)

1. What is Python mainly used for?

Python is used for web development, data science, machine learning, automation, and software testing. Its versatility makes it one of the top programming languages globally.


2. Is Python dynamically typed?

Yes ✅, Python is dynamically typed, meaning you don’t have to declare the data type of a variable before using it. Python determines the type automatically at runtime.

Example:

x = 10       # int
x = "Hello"  # str

3. What is explicit conversion in Python?

Explicit conversion, also known as type casting, is when a programmer manually changes a data type using functions like int(), float(), or str().


4. What is the difference between implicit and explicit type conversion?

FeatureImplicit ConversionExplicit Conversion
Who performs it?Python (automatically)Programmer (manually)
Function needed?NoYes (int(), str(), etc.)
Example5 + 2.57.5int("25")25

5. Why are data types important in Python?

Data types determine what kind of operations can be performed on values and how Python stores them in memory.
Example: You can add integers but concatenate strings.


🚀 Final Thoughts

Python’s clean syntax and flexibility make it the perfect language for beginners and professionals alike.
Understanding data types and explicit conversion is an essential foundation for mastering Python programming. Once you’re comfortable with these basics, you can move on to exciting topics like loops, functions, and object-oriented programming (OOP).