Using Libraries (NumPy, Pandas)
One of Python's greatest strengths is its massive ecosystem of libraries. Libraries are pre-written code that you can use to add advanced features to your programs.
NumPy
NumPy is used for scientific computing and working with large arrays of numbers.
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr * 2) # Output: [2, 4, 6, 8, 10]
Pandas
Pandas is the go-to library for data analysis and manipulation. It introduces the DataFrame, which is like a spreadsheet for Python.
import pandas as pd
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Score': [85, 92, 78]
}
df = pd.DataFrame(data)
print(df)