Lesson · 40 min · Free
Python Programming: Get Started
Python Programming: Get Started Python Programming: Get Started Welcome to the first lesson of "Python for Pharmaceutical Research"! In this course, we will explore how Python, a versatile and powerful programming langua
Python Programming: Get Started
Welcome to the first lesson of "Python for Pharmaceutical Research"! In this course, we will explore how Python, a versatile and powerful programming language, can be leveraged to streamline and enhance various aspects of pharmaceutical research, from data analysis to automation and beyond. This introductory lesson will get you set up with Python, understand its fundamental concepts, and write your first lines of code. Python's popularity in scientific fields, including pharmaceuticals and biotechnology, stems from its readability, extensive libraries for scientific computing (e.g., NumPy, SciPy, Pandas), and its strong community support. Unlike some other programming languages, Python emphasizes code readability and a syntax that allows developers to express concepts in fewer lines of code, making it an excellent choice for researchers who may not have a deep background in computer science.
Setting Up Your Python Environment
Before we dive into coding, you need to set up your Python environment. The most common and recommended way for scientific computing is to use Anaconda. Anaconda is a free and open-source distribution of Python and R programming languages for scientific computing (data science, machine learning applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment. Steps to Install Anaconda: Go to the official Anaconda website: https://www.anaconda.com/products/individual Download the appropriate installer for your operating system (Windows, macOS, or Linux). Follow the installation instructions. It's generally recommended to accept the default settings, including adding Anaconda to your PATH environment variable (if prompted). Once Anaconda is installed, you'll have access to Python, the Conda package manager, and a powerful integrated development environment (IDE) called Jupyter Notebook. Jupyter Notebook allows you to create and share documents that contain live code, equations, visualizations, and narrative text. It's an ideal environment for exploratory data analysis and sharing your research findings. To launch Jupyter Notebook, open your system's terminal or command prompt and type: jupyter notebook This command will open a new tab in your web browser, presenting the Jupyter Notebook interface.
Your First Python Code: "Hello, Pharma World!"
Let's write our first Python program. In a new Jupyter Notebook, type the following code into a cell and run it (Shift + Enter): print("Hello, Pharma World!") This simple line of code uses the built-in print() function to display the string "Hello, Pharma World!" to the output. This function is fundamental for displaying information and debugging your code.
Variables and Data Types
In programming, variables are used to store data. Think of them as named containers for values. Python is dynamically typed, meaning you don't need to declare the type of a variable explicitly; Python infers it at runtime. Common data types you'll encounter include: Integers ( int ): Whole numbers (e.g., 10 , -5 ) Floating-point numbers ( float ): Numbers with decimal points (e.g., 3.14 , 0.001 ) Strings ( str ): Sequences of characters, enclosed in single or double quotes (e.g., "DNA" , 'protein' ) Booleans ( bool ): Represent truth values, either True or False Let's see an example of assigning values to variables and performing a simple calculation: # Define variables related to drug concentration initial_concentration = 100.0 # micrograms/mL time_point_hours = 24 decay_rate = 0.05 # per hour # Calculate concentration after decay (simple exponential model) # C(t) = C0 * e^(-kt) - For simplicity, let's use a linear approximation for now # We will learn about more complex math functions later concentration_after_24h = initial_concentration * (1 - (decay_rate * time_point_hours)) print(f"Initial Concentration: {initial_concentration} ug/mL") print(f"Concentration after {time_point_hours} hours: {concentration_after_24h} ug/mL") In this example, we define three variables: initial_concentration (a float), time_point_hours (an integer), and decay_rate (a float). We then perform a simple calculation and use an f-string (formatted string literal) to print the results in a readable format. F-strings are a powerful way to embed expressions inside string literals.
Key Takeaways
Python is a versatile and readable programming language, excellent for scientific research. Anaconda is the recommended distribution for setting up your Python environment, providing Python, Conda, and Jupyter Notebook. The print() function is used to display output. Variables store data and Python automatically infers their data type (e.g., int , float , str , bool ). Jupyter Notebook provides an interactive environment for writing and executing Python code.
Practice Exercise
Open a new Jupyter Notebook. Create two variables: one named drug_name and assign it the string value of your favorite drug (e.g., "Aspirin"), and another named dosage_mg and assign it an integer value representing a typical dosage (e.g., 500). Then, use the print() function with an f-string to output a sentence like: "The drug [drug_name] is commonly prescribed at a dosage of [dosage_mg] mg."
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 →