Lesson · 40 min · Free
Python Get Started
Python Get Started 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 Get Started
Welcome to the first practical lesson of "The Complete Python Bootcamp: Basics to Pharma & Data Science"! In this module, we'll lay the foundational groundwork for your Python journey. Python is an incredibly versatile and powerful programming language, widely adopted in various fields, including data science, machine learning, web development, and critically, in pharmaceutical and biotechnological research for data analysis, modeling, and automation. Its readability and extensive libraries make it an excellent choice for scientists and researchers who may not have a traditional computer science background. Before diving into complex algorithms or bioinformatics pipelines, it's essential to understand the basics: how to write and execute simple Python code. This lesson will guide you through your first steps, ensuring you can interact with the Python interpreter and run basic scripts. We'll focus on fundamental concepts like printing output and understanding variables, which are the building blocks of any program.
Your First Python Program: "Hello, Pharma!"
The traditional first program in any language is often "Hello, World!". We'll give it a pharmaceutical twist. To write and execute Python code, you typically use an interpreter. When you install Python, you get access to this interpreter. You can run Python in an interactive shell (typing commands directly) or by writing scripts (saving commands in a .py file and running the file). Let's start with the simplest interaction: printing text to the console. The print() function is Python's standard way to display output. Whatever you put inside the parentheses will be shown on your screen. # This is a comment in Python. It's ignored by the interpreter. # We use comments to explain our code. print("Hello, Pharma!") print("Welcome to Python for Data Science!") When you run this code (either in an interactive shell or by saving it as a .py file and executing it from your terminal), you will see the two messages displayed on separate lines. Notice that text (strings) must be enclosed in single or double quotes. This tells Python that "Hello, Pharma!" is a sequence of characters, not a command or a variable name.
Variables: Storing Information
In programming, variables are like containers for storing data values. They allow you to refer to data by a name, making your code more readable and manageable. When you want to store a piece of information – be it a patient ID, a drug concentration, or the result of a calculation – you use a variable. Python is dynamically typed, meaning you don't need to explicitly declare the type of a variable; Python figures it out at runtime. Here's how you declare and use variables: # Declaring variables patient_id = "P00123" drug_name = "Aspirin" dose_mg = 100 is_active = True # Boolean variable (True/False) # Printing variable values print("Patient ID:", patient_id) print("Administered Drug:", drug_name) print("Dose (mg):", dose_mg) print("Is the patient currently active in trial?", is_active) # You can also perform operations with variables total_dose_in_grams = dose_mg / 1000 print("Total dose (grams):", total_dose_in_grams) In this example, we've created several variables to store different types of data: a string ( patient_id , drug_name ), an integer ( dose_mg ), a boolean ( is_active ), and a float ( total_dose_in_grams , resulting from a division). The print() function can take multiple arguments separated by commas; it will print them with a space in between.
Key Takeaways
Python is a high-level, versatile programming language used extensively in data science and biotech. The print() function is used to display output to the console. Strings (text) in Python are enclosed in single or double quotes. Variables are used to store data, making code more organized and reusable. Python is dynamically typed; you don't need to declare a variable's type explicitly. Comments (lines starting with # ) are ignored by Python and are used to explain code.
Practice Exercise: Patient Profile
Your task is to create a small Python script that stores and prints a basic profile for a hypothetical patient in a clinical trial. Define variables for the following information: patient_name (string), age (integer), weight_kg (float), and is_on_placebo (boolean). Assign appropriate values to these variables. Then, use the print() function to display each piece of information clearly, similar to how we printed the drug information in the examples above. Additionally, calculate and print the patient's age in months.
Watch the full lesson — free
This topic is part of The Complete Python Bootcamp: Basics to Pharma & Data Science, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →