Lesson · 40 min · Free
Python Intro & Basics
Python Intro & Basics Python Intro & Basics Welcome to the first module of "Python for Pharmaceutical Research"! In this lesson, we'll introduce you to Python, a versatile and powerful programming language, and cover its
Python Intro & Basics
Welcome to the first module of "Python for Pharmaceutical Research"! In this lesson, we'll introduce you to Python, a versatile and powerful programming language, and cover its fundamental concepts. While programming might seem daunting at first, Python's clean syntax and extensive libraries make it an excellent choice for scientific computing, data analysis, and automation – all critical aspects of modern pharmaceutical research. Python is an interpreted, high-level, general-purpose programming language. Its design philosophy emphasizes code readability with its notable use of significant indentation. For pharmaceutical research, Python offers numerous advantages: it can handle large datasets, perform complex statistical analyses, automate repetitive tasks (like data extraction from various sources), develop predictive models for drug discovery, and even control laboratory equipment. Understanding these basics will lay a strong foundation for more advanced topics later in this course.
Getting Started: Variables, Data Types, and Basic Operations
At the heart of any programming language are variables and data types. A variable is essentially a named storage location for data. In Python, you don't need to explicitly declare the type of a variable; Python infers it automatically. We'll primarily work with a few core data types: Integers ( int ): Whole numbers (e.g., 10 , -5 , 0 ). Useful for counts, dosages, or trial numbers. Floating-point numbers ( float ): Numbers with decimal points (e.g., 3.14 , 2.5e-3 ). Essential for concentrations, p-values, or kinetic constants. Strings ( str ): Sequences of characters (e.g., "Acetaminophen" , "Clinical Trial Phase III" ). Used for names, labels, or textual data. Booleans ( bool ): Represent truth values ( True or False ). Crucial for conditional logic (e.g., "Is drug effective?", "Is patient enrolled?"). Let's look at some basic operations with these data types. You can assign values to variables using the = operator, and perform arithmetic operations just like in mathematics. # Assigning variables drug_name = "Ibuprofen" dose_mg = 200 patient_weight_kg = 75.5 is_approved = True # Performing basic arithmetic total_dose_per_day = dose_mg * 3 # Assuming 3 doses per day concentration_mM = 10.5 / 1000 # Converting micromolar to millimolar print(f"Drug: {drug_name}") print(f"Daily Dose: {total_dose_per_day} mg") print(f"Patient Weight: {patient_weight_kg} kg") print(f"Is Approved: {is_approved}") print(f"Concentration: {concentration_mM} mM") Another fundamental concept is how to get input from a user and display output. The input() function allows you to prompt the user for data, and the print() function displays information to the console. The f-string (formatted string literal) used in the example above is a powerful way to embed expressions inside string literals. # Getting user input patient_id = input("Enter patient ID: ") age_str = input("Enter patient age: ") age = int(age_str) # Convert string input to integer # Displaying output print(f"Patient ID: {patient_id}") print(f"Patient Age: {age} years") # Conditional logic based on age if age >= 18: print("Patient is an adult.") else: print("Patient is a minor.") Notice the if and else statements in the second code example. These are control flow statements that allow your program to make decisions. Indentation is crucial in Python; it defines code blocks. All lines belonging to an if or else block must be indented consistently.
Key Takeaways
Python is a high-level, readable language suitable for pharmaceutical research. Variables store data, and Python infers their types ( int , float , str , bool ). Basic arithmetic operations are straightforward. The print() function displays output, and input() gathers user data. f-strings provide an easy way to format output. Indentation is critical for defining code blocks and control flow (e.g., if/else statements).
Practice Exercise
Write a Python script that prompts the user for the name of a drug, its standard dose in milligrams (mg), and the number of times per day it should be administered. Calculate and print the total daily dose in both milligrams (mg) and grams (g). Ensure your output is clearly labeled and uses f-strings for formatting.
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 →