- In our daily life we use numbers and text to communicate and perform certain processes.
- TThe primitive data types are numbers and text
- Objects such as images and files are also part of data types.
Identify the data types for the following
- Total students present in the class
- Course code of a subject
- Room temperature
- NYU student ID
- Home address
- Day of the week (Sunday, Monday, etc)
- Price of a book
- CGPA of a student
For example, the variable fname is used to store the first name of a person. The first name of a person is of type text or string.
Rules for naming a Variable
- Must begin with a letter (a - z, A - Z) or (_)
- Other characters can be letters, numbers or _
- Case Sensitive. Upper case is different from lower case
- Can be any (reasonable) length
- There are some reserved words which you cannot use as a variable name because Python uses them for other things. Example: for, import, in, range
Identify valid variable names from the following
- Total students
- as, for, in, import (reserved words in Python)
What if you want to change the size of the square from 100 to 50 dots?
- Solution 1: Replace all 100 by 50
- Solution 2: Use a variable instead of a value!How? X = 100
Using Variables, extended
- Let us go back to our square example.
- You noticed that we used 100 as the length of the square.
- Now, we will use a variable L instead of 100.
Convert the following mathematical expression to Python expression
Exercise on Precedence Rules
Evaluate the following expressions using the operator precedence.
For more details, please contact me here.
Date of last modification: 2021