Learn Python Topics for Data Analysis: Part - 1

Learn Python Topics for Data Analysis: Part - 1

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:

  • int: Integer numbers (e.g., 1, 10, -5).
  • float: Floating-point numbers (e.g., 3.14, -0.001).
  • str: Strings of characters, enclosed in single or double quotes (e.g., "hello", 'world').
  • list: Ordered, mutable collections of items (e.g., [1, 2, 3], ['a', 'b', 'c']).
  • tuple: Ordered, immutable collections of items (e.g., (1, 2, 3), ('a', 'b', 'c')).
  • bool: Boolean values, either True or False.

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.


要查看或添加评论,请登录

SHUBHAM CHOUDHURY的更多文章

社区洞察

其他会员也浏览了