Lesson · 40 min · Free
Python Basics: Intro
Python Basics: Intro 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; } code { font-family
Python Basics: Intro
Welcome to the introductory module for Python within our "Python for Pharmaceutical Research" course. Python has emerged as an indispensable tool in various scientific disciplines, including pharmaceutical research, due to its readability, extensive libraries, and robust community support. For those coming from a background in pharmacy or biotechnology, understanding the fundamentals of programming can significantly enhance your ability to analyze data, automate tasks, and develop computational models relevant to drug discovery, development, and clinical trials. This initial lesson will introduce you to the very basics of Python: how to output information, define variables, and perform simple arithmetic operations. Think of these as the foundational building blocks upon which all more complex analyses and scripts will be constructed. Mastery of these concepts is crucial before moving on to more specialized topics like data manipulation with Pandas or scientific computing with NumPy, which are central to pharmaceutical research applications.
Getting Started with Python
Python is an interpreted language, meaning you can execute code line by line, which is excellent for learning and rapid prototyping. The most fundamental operation in any programming language is often printing output to the console. In Python, this is achieved using the print() function. Let's look at a simple example to display a message. This might seem trivial, but it's your first interaction with Python's syntax and function calls. # This is a comment in Python. It's ignored by the interpreter. # Use comments to explain your code! print("Hello, pharmaceutical researchers!") print("Welcome to Python for drug discovery.") When you run this code, the text inside the parentheses and quotes will appear on your screen. The # symbol denotes a comment, which is ignored by the Python interpreter and is used by programmers to add explanatory notes to their code, improving readability and maintainability – a critical practice in collaborative research environments. Next, let's explore variables. Variables are named storage locations that hold data. In pharmaceutical research, you might use variables to store drug concentrations, patient IDs, experimental results, or molecular weights. Python is dynamically typed, meaning you don't need to declare the type of a variable before using it; Python infers the type based on the value assigned. # Assigning a string to a variable drug_name = "Aspirin" print("The current drug being studied is:", drug_name) # Assigning an integer (whole number) to a variable dosage_mg = 100 print("The dosage is:", dosage_mg, "mg") # Assigning a float (decimal number) to a variable half_life_hours = 2.5 print("The half-life is:", half_life_hours, "hours") # Performing a simple arithmetic operation num_patients = 50 num_treatment_groups = 2 patients_per_group = num_patients / num_treatment_groups print("Patients per treatment group:", patients_per_group) # Output will be 25.0 (a float) In the examples above, we've demonstrated assigning different types of data (text, whole numbers, decimal numbers) to variables and then using those variables in print() statements. Notice how Python automatically handles the division operation, even converting the result to a float if necessary. This flexibility makes Python very powerful for handling diverse datasets encountered in pharmaceutical R&D.
Key Takeaways
Python is an interpreted language , allowing for line-by-line execution. The print() function is used to display output to the console. Comments, denoted by # , are crucial for code readability and documentation. Variables are named containers for storing data (e.g., numbers, text). Python is dynamically typed , meaning variable types are inferred. Basic arithmetic operations ( + , - , * , / ) work as expected.
Practice Exercise
Your task is to write a short Python script that simulates a simple calculation related to drug formulation. Imagine you have a stock solution of a compound and you need to calculate the amount of active pharmaceutical ingredient (API) in a specific volume. Define two variables: one for the stock_concentration_mg_per_ml (e.g., 25 mg/mL) and another for the volume_ml (e.g., 10 mL). Calculate the total_api_mg and then print a descriptive statement showing your result. For an extra challenge, also calculate how many 50_mg_doses could be prepared from this total API and print that result.
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 →