April 24, 2026

Variables & Data Types in Python (with Pharma-Based Examples)

Variables & Data Types in Python Explained for Pharmacy Students (With Dose & PK Examples)

Understanding variables and data types is the foundation of Python programming. In pharmaceutical sciences, these concepts are used to store and manipulate values such as drug dose, concentration, patient data, and clinical observations.


๐Ÿ”ท What is a Variable in Python?

A variable is a container used to store data values.

dose = 500

Here, dose is a variable storing the value 500 mg.

๐Ÿ’ก Key Insight: Python does not require explicit declaration of variable type.

๐Ÿ”ท Rules for Naming Variables

  • Must start with a letter or underscore
  • Cannot start with a number
  • No spaces allowed
  • Case-sensitive (Dose โ‰  dose)

๐Ÿ”ท Data Types in Python

Data types define the type of value a variable can store.

Data TypeExamplePharma Example
Integer (int)dose = 500Dose in mg
Floatconc = 2.5Drug concentration (mg/mL)
Stringdrug = “Paracetamol”Drug name
Booleanis_safe = TrueDrug safety status

๐Ÿ”ท Checking Data Type

dose = 500
print(type(dose))

This will display the type of the variable.


๐Ÿ”ท Type Casting

Type casting means converting one data type into another.

dose = "500"
dose_int = int(dose)

Here, string “500” is converted into integer 500.


๐Ÿ”ท Assigning Multiple Variables

dose, conc, drug = 500, 2.5, "Paracetamol"

๐Ÿ’Š Pharmaceutical Application

Consider a pharmacokinetic study:

dose = 500          # mg
concentration = 2.5 # mg/mL
patient_name = "John"
is_toxic = False

These variables help in storing and analyzing patient-specific drug data.


๐Ÿง  Memory Tricks

  • int โ†’ Whole numbers (Dose)
  • float โ†’ Decimal values (Concentration)
  • string โ†’ Text (Drug name)
  • bool โ†’ True/False (Safety)

๐Ÿงช Practice Exercise

dose = 650
drug = "Ibuprofen"
conc = 1.8

print(dose, drug, conc)

๐Ÿ“ MCQs

  1. Which data type is used for decimal values?
    a) int
    b) float
    c) string
    d) bool
    Answer: b

  2. Which of the following is a valid variable?
    a) 1dose
    b) dose_1
    c) dose-1
    d) dose 1
    Answer: b

  3. What will be the type of “500”?
    a) int
    b) float
    c) string
    d) bool
    Answer: c

โ“ FAQs

Why are data types important?

They ensure correct operations and data handling in programs.

Can Python change data type automatically?

Yes, Python supports dynamic typing.


๐Ÿ“ฅ Download Practice Problems & Notes

Enhance your learning with pharma-based coding exercises.


โžก Next Topic: Operators in Python โ†’

Unit 1 Blog Series:

  1. Installing Python
  2. Installing IDEs (Jupyter, VS Code, PyCharm)
  3. Variables and data types in Python (You are on this page page)
  4. Operators in Python
  5. Input & Output
  6. String Manipulation
  7. Libraries in Python

Question Bank : Unit 1 Python Programming Basics

For more details: Basics of Python Programming for Pharmaceutical Sciences (Theory)