Lesson · 40 min · Free
Python Introduction: From Basics to Pharma
Python Introduction: From Basics to Pharma body { font-family: sans-serif; line-height: 1.6; margin: 20px; } h1, h2 { color: #2c3e50; } pre { background-color: #ecf0f1; padding: 15px; border-radius: 5px; overflow-x: auto
Python Introduction: From Basics to Pharma
Welcome to the first lesson of "Python for Data Science"! In this module, we'll embark on our journey with Python, starting from its fundamental concepts and progressively exploring its relevance and applications within the pharmaceutical and biotechnology sectors. Python's versatility, readability, and extensive libraries make it an indispensable tool for data analysis, modeling, and automation in modern scientific research. For those coming from a scientific background, particularly pharmacy or biotech, you'll find Python's intuitive syntax remarkably similar to mathematical notation or pseudo-code, which aids in a rapid learning curve. We'll cover basic data types, variables, and control flow, laying the groundwork for more complex data science tasks later in the course.
Why Python for Pharma/Biotech?
Python's utility in the pharmaceutical and biotechnology industries is vast and ever-growing. From managing clinical trial data and analyzing genomic sequences to developing predictive models for drug discovery and optimizing manufacturing processes, Python offers powerful solutions. Its open-source nature fosters a vibrant community, leading to specialized libraries (e.g., Biopython for bioinformatics, SciPy for scientific computing, Pandas for data manipulation) that directly address the unique challenges of these fields. Understanding Python empowers you to not just consume, but actively contribute to the data-driven advancements shaping the future of medicine.
Basic Data Types and Variables
Let's begin with the building blocks of any programming language: data types and variables. Python automatically infers the data type of a variable based on the value assigned to it, making it very flexible. Common data types include integers (whole numbers), floats (decimal numbers), strings (text), and booleans (True/False). # Assigning an integer to a variable patient_id = 1001 print(f"Patient ID: {patient_id}, Type: {type(patient_id)}") # Assigning a float to a variable drug_concentration_mg_per_ml = 2.5 print(f"Drug Concentration: {drug_concentration_mg_per_ml}, Type: {type(drug_concentration_mg_per_ml)}") # Assigning a string to a variable drug_name = "Paracetamol" print(f"Drug Name: {drug_name}, Type: {type(drug_name)}") # Assigning a boolean to a variable is_approved = True print(f"Is Approved: {is_approved}, Type: {type(is_approved)}") # Basic arithmetic operations dose_per_kg = 5 # mg/kg patient_weight_kg = 70 total_dose_mg = dose_per_kg * patient_weight_kg print(f"Total Dose for 70kg patient: {total_dose_mg} mg")
Conditional Statements (if-elif-else)
Conditional statements allow your program to make decisions based on certain conditions. This is fundamental for creating logic in your scripts, such as checking if a drug dosage is within a safe range or categorizing patient data based on specific criteria. # Example: Dosage check based on patient age patient_age = 65 prescribed_dose_mg = 500 if patient_age = 60 print("Geriatric patient. Consider lower doses due to potential impaired metabolism.") safe_max_dose_mg = 750 if prescribed_dose_mg > safe_max_dose_mg: print(f"WARNING: Prescribed dose ({prescribed_dose_mg}mg) exceeds recommended max for this age group ({safe_max_dose_mg}mg).") else: print(f"Prescribed dose ({prescribed_dose_mg}mg) is within the safe range for this age group.")
Key Takeaways
Python is a versatile and readable programming language, highly valued in data science, especially in pharma/biotech. It supports fundamental data types like integers, floats, strings, and booleans, which are the basis for all data manipulation. Variables are used to store data, and Python automatically infers their type. Conditional statements ( if , elif , else ) enable programs to execute different code blocks based on conditions, crucial for decision-making logic. Python's extensive library ecosystem (e.g., Biopython, SciPy, Pandas) provides specialized tools for scientific and pharmaceutical applications.
Practice Exercise: Drug Interaction Check
Imagine you are developing a simple system to flag potential drug interactions. Write a Python script that takes two drug names (as strings) and a patient's age (as an integer). For simplicity, let's assume a known interaction between "DrugA" and "DrugB" that is particularly severe for patients under 12 or over 65. Your script should: Define two variables for drug1_name and drug2_name , and one for patient_age . Use conditional statements to check if both drug1_name is "DrugA" and drug2_name is "DrugB" (or vice-versa). If this specific interaction is present, further check if the patient_age is less than 12 or greater than 65. Print an appropriate warning message if a severe interaction is detected for the age group, a general interaction warning if it's "DrugA" and "DrugB" but not in the severe age group, and a "No known severe interaction." message otherwise.
Watch the full lesson — free
This topic is part of Python for Data Science, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →