These free B.Pharm notes on python variables data types and operators cover chapter 2 of Basics of Python Programming for Pharmaceutical Sciences (BP101T), a first-semester subject. Read the key points below, then study the complete chapter PDF. You can browse every chapter in the Basics of Python Programming for Pharmaceutical Sciences category.
Table of Contents
Read the following document for full information
Overview of python variables data types and operators
These notes explain Python variables, dynamic typing and the rules for naming variables, followed by the main data types (int, float, str and bool) and type checking with type(). They then cover type casting with implicit and explicit conversion, the seven groups of basic operators, and input and output operations using input(), print(), the end parameter, f-strings and escape characters.
Key points on python variables data types and operators
- A variable is a name used to store a value, and Python works out its type automatically from the assigned value, which is called dynamic typing.
- A variable name must begin with a letter or underscore, cannot begin with a digit, cannot be a reserved keyword and is case-sensitive.
- Type casting changes a value from one data type to another using int(), float(), str() or bool(), and converting a float to an int discards the decimal part.
- In implicit conversion Python changes the type automatically, for example 5 + 2.5 gives the float 7.5, while in explicit conversion the programmer calls a function such as int().
- The input() function always stores what the user types as a string, so numeric input must be converted, for example int(input(“Enter your age: “)).
Relevance to pharmacy practice
Every pharmacy calculation, from a patient’s age to a dose in milligrams, needs the right data type and the correct operators to give accurate results. Knowing how to take input and show formatted output lets a student write simple programs that accept patient values and display clear results.
Every chapter in this subject builds on the one before it, so do not skip topics that look simple. Definitions, principles, procedures and examples are the parts that examiners return to most often, and a clear understanding here will also make later subjects easier to follow in the coming semesters.
Frequently asked questions on python variables data types and operators
What are the main data types in Python?
The main data types are integer (int) for whole numbers, float for numbers with a decimal point, string (str) for text, and boolean (bool), which holds only True or False.
What is the difference between implicit and explicit type conversion?
In implicit conversion Python changes the data type automatically, such as when an int and a float are added. In explicit conversion the programmer deliberately calls a function like int() or float().
What is an f-string in Python?
An f-string is a string prefixed with the letter f in which variable names are placed inside curly braces, so their values are inserted directly into the text when it is printed.
Quick revision checklist
Use this self-test after reading the chapter on python variables data types and operators. If you can do all of the following without looking at your notes, you are ready for the exam.
- I can explain: what a variable is and dynamic typing
- I can explain: rules for naming Python variables
- I can explain: int, float, str and bool data types
- I can explain: implicit and explicit type casting
- I can explain: the seven types of Python operators
Study and exam tips
Start by reading the chapter once for the overall idea, then revise python variables data types and operators using headings, definitions, principles, reactions and examples. Short-answer questions in the university exam usually ask for definitions, principles, procedures, reactions and uses, so write these in your own words and practise the equations, tables and flow charts that the chapter has.
For wider reading, standard books and open resources such as the NCBI Bookshelf help you confirm terms and see more examples. Revise python variables data types and operators again a day later and again a week later, because spaced revision improves long-term memory.
This page is part of the Basics of Python Programming for Pharmaceutical Sciences series for first-semester B.Pharm students on B.Pharm Guru, where every chapter has a short summary and a full PDF. Bookmark this page and share it with classmates who are preparing for the same exam.
Related notes: 4. INTRODUCTION TO STANDARD LIBRARIES AND THIRD-PARTY LIBRARIES, INSTALLING AND UNINSTALLING LIBRARIES, 5. CONDITIONAL STATEMENTS AND NESTED CONDITIONS.
Next: 3. BASIC STRING OPERATIONS AND MANIPULATION TECHNIQUES. Back to the Basics of Python Programming for Pharmaceutical Sciences category.




