Skip to content

W3: Data Types, Variables, Arithmetic Operators

Data Types


Above are some data types that we’ll be learning in COMP10001. Highlighted are what we’ve learnt from the lectures so far. Python offers many more built-in data types that can be explored here.

String Operations, Functions and Methods

D1. What is a “data type”? Can the data type of an object change?

D2: As a class, fill in the below table with the data types we have studied so far. What is the difference between the second and third type, both being numerical?

TypeExampleWhat does it store?What can we do with it (functions, operations…)?How do we convert to it?
"Hello"
123
3.1415
True

E1. Look at the following customer data form, and decide which data types (str, int, float, or bool) should be used to store each field.

E2. Evaluate the following

Arithmetic Operators

D3. What is an “operator”? Which operators have we learned so far and what do they do?

D4. What is “operator overloading”? What is the difference between using + with numerical types and strings/sequences?

Variables

D5. What is a “variable”? How do we use variables and why are they helpful?

E3. Evaluate the following given the assignments a = 1, b = 2, c = 2.0:

E4. What is the output of the following? Why?

Extra Questions

EQ6. How does the input() function work?

EQ7. What is a literal?

EQ8. Why does 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1 equal 0.9999999999999999 and not 1.0?

Problems

Problem 1

Problem 2

Problem 3