Learn Python Topics for Data Analysis: Part - 1
SHUBHAM CHOUDHURY
UGC-NET (Assistant Professor) Qualified | Working on Artificial Intelligence, Machine Learning, Deep Learning & LLMs | Teaching & Mentoring College Students
Introduction to Python
1. Variables, Data Types, and Basic Operations:
Variables:
In Python, variables are used to store data values. Variables are created when they are first assigned a value. Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.
age = 25
name = "John"
Data Types:
Python supports various data types, including:
height = 1.75 # float
colors = ['red', 'green', 'blue'] # list
Basic Operations:
Python supports various basic arithmetic operations:
result = 10 + 5 # Addition
result = 10 - 5 # Subtraction
result = 10 * 5 # Multiplication
result = 10 / 5 # Division
result = 10 // 5 # Floor division
result = 10 % 5 # Modulus (remainder of division)
result = 10 ** 5 # Exponentiation
2. Control Structures (If Statements, Loops):
If Statements:
Conditional statements allow you to make decisions in your code based on certain conditions.
领英推荐
age = 18
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Loops (For and While):
Loops are used for iterating over a sequence (string, list, tuple, dictionary, etc.).
fruits = ['apple', 'banana', 'orange']
for fruit in fruits:
print(fruit)
3. Functions and Modules:
Functions:
Functions are blocks of reusable code that perform a specific task. They allow you to break down your program into smaller, manageable pieces.
def greet(name):
return f"Hello, {name}!"
result = greet("Alice")
Modules:
Modules allow you to organize code into separate files and reuse it across multiple projects.
# mymodule.py
def multiply(x, y):
return x * y
# main script
import mymodule
result = mymodule.multiply(3, 4)
Understanding these fundamental concepts in detail is essential for building a strong foundation in Python programming. They provide you with the tools to manipulate data, control the flow of your program, and organize your code effectively.
Stay tuned for more enriching insights into Python's data analysis ecosystem in the upcoming days.