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.
๐ท 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 Type | Example | Pharma Example |
|---|---|---|
| Integer (int) | dose = 500 | Dose in mg |
| Float | conc = 2.5 | Drug concentration (mg/mL) |
| String | drug = “Paracetamol” | Drug name |
| Boolean | is_safe = True | Drug 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
- Which data type is used for decimal values?
a) int
b) float
c) string
d) bool
Answer: b - Which of the following is a valid variable?
a) 1dose
b) dose_1
c) dose-1
d) dose 1
Answer: b - 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:
- Installing Python
- Installing IDEs (Jupyter, VS Code, PyCharm)
- Variables and data types in Python (You are on this page page)
- Operators in Python
- Input & Output
- String Manipulation
- Libraries in Python
Question Bank : Unit 1 Python Programming Basics
For more details: Basics of Python Programming for Pharmaceutical Sciences (Theory)