Lesson · 40 min · Free
Python Programming Basics
Python Programming Basics body { font-family: sans-serif; line-height: 1.6; margin: 20px; } h1, h2 { color: #2c3e50; } pre, code { background-color: #ecf0f1; padding: 10px; border-radius: 5px; overflow-x: auto; } ul { li
Python Programming Basics
Welcome to the foundational module of "Python for Pharmaceutical Research." In this lesson, we will introduce you to the absolute basics of Python programming. Even if you have no prior coding experience, this module will equip you with the fundamental concepts and syntax necessary to start writing simple Python scripts. Python's readability and extensive libraries make it an invaluable tool for data analysis, automation, and modeling in pharmaceutical sciences. We'll cover core concepts such as variables, data types, basic operations, and how to execute your first Python code. Understanding these building blocks is crucial before we delve into more complex topics relevant to drug discovery and development.
Getting Started with Python
Python is an interpreted language, meaning you can execute commands line by line or run entire scripts. For this course, we recommend using an Integrated Development Environment (IDE) like Jupyter Notebooks or VS Code, which provide an interactive environment for writing and testing your code. However, for these initial examples, you can simply use a Python interpreter directly.
Variables and Data Types
A variable is a named storage location in a computer program that holds a value. In Python, you don't need to declare the type of a variable explicitly; Python infers it. Common data types include: Integers ( int ): Whole numbers (e.g., 10 , -5 ) Floats ( float ): Numbers with decimal points (e.g., 3.14 , 0.5 ) Strings ( str ): Sequences of characters, enclosed in single or double quotes (e.g., "Hello" , 'Drug A' ) Booleans ( bool ): Represents truth values, either True or False Let's look at some examples of assigning values to variables and checking their types: # Assigning an integer patient_id = 101 print(f"Patient ID: {patient_id}, Type: {type(patient_id)}") # Assigning a float drug_concentration_mM = 0.75 print(f"Drug Concentration: {drug_concentration_mM} mM, Type: {type(drug_concentration_mM)}") # Assigning a string compound_name = "Acetaminophen" print(f"Compound Name: {compound_name}, Type: {type(compound_name)}") # Assigning a boolean is_active_compound = True print(f"Is Active Compound: {is_active_compound}, Type: {type(is_active_compound)}")
Basic Operations
Python supports standard arithmetic operations, string concatenation, and comparison operators. These are fundamental for manipulating data. Arithmetic Operators: + (addition), - (subtraction), * (multiplication), / (division), ** (exponentiation), % (modulo - remainder) String Concatenation: Use the + operator to combine strings. Comparison Operators: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to). These return boolean values. Here are some examples: # Arithmetic operations dose_mg = 500 number_of_doses = 2 total_daily_intake_mg = dose_mg * number_of_doses print(f"Total daily intake: {total_daily_intake_mg} mg") half_life_hours = 8.5 conversion_factor = 60 # minutes per hour half_life_minutes = half_life_hours * conversion_factor print(f"Half-life in minutes: {half_life_minutes} minutes") # String concatenation first_name = "Alice" last_name = "Smith" full_name = first_name + " " + last_name print(f"Full Name: {full_name}") # Comparison operations temperature_celsius = 37.5 is_fever = temperature_celsius > 37.0 print(f"Is fever present? {is_fever}") drug_a_potency = 0.85 drug_b_potency = 0.92 is_drug_a_more_potent = drug_a_potency > drug_b_potency print(f"Is Drug A more potent than Drug B? {is_drug_a_more_potent}") These basic operations form the bedrock of all more complex computations you will perform in pharmaceutical research. Practice using them to become comfortable with Python's syntax.
Key Takeaways
Python is an interpreted language, easy to read and write. Variables store data, and Python infers their type (e.g., int , float , str , bool ). The print() function is essential for displaying output and debugging. Basic arithmetic, string concatenation, and comparison operators are fundamental for data manipulation. Familiarize yourself with Python's basic syntax as it will be used throughout the course.
Practice Exercise: Patient Data Summary
Imagine you are tracking a patient's initial response to a new drug. Create Python variables for the following information: Patient's initials (e.g., "JS") Patient's age (e.g., 62) Initial blood pressure (systolic, e.g., 145) Initial blood pressure (diastolic, e.g., 90) A boolean indicating if the patient has a history of hypertension (e.g., True ) The dosage of the new drug (e.g., 10.5 mg) Then, perform the following operations and print the results: Concatenate the patient's initials with a descriptive string like "Patient Initials: ". Calculate the patient's pulse pressure (systolic - diastolic) and print it. Determine if the patient's systolic blood pressure is greater than 140 and print the boolean result. Print a summary sentence combining the patient's initials, age, and drug dosage (e.g., "Patient JS, aged 62, is receiving 10.5 mg of the drug.").
Watch the full lesson — free
This topic is part of Python for Pharmaceutical Research, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →