top of page

Python Tutorial and Programming Practice Set 1

Question 1:

What are the differences between operators and values in the following?









* : will perform multiplication operation on values

‘hello’ : is a string constant (made of sequenced order of characters)whose value do not change in the entire program.

-87.8 : is a float constant with negative value

- : is an operator which performs subtraction operation on values

/ : is an operator which performs division operation on values

+ : is an operator which performs addition operation on values

6 : is a integer constant

Question 2:

What is the difference between string and variable?




spam is a variable which can take any value as int, string, float, etc and can be changed at any time

‘spam’is a string constant which remains same throughout .

Question 3:

Describe three different data forms.


Assuming data forms to be data types,

Int-integer which takes integer values

float-float which takes float values

str-String which takes sequence of characters

Question 4:

What makes up an expression? What are the functions of all expressions?


Expression is a combination of values, operators and assignment. The functions of all expressions is to be give a definite output once the expression is processed .

Question 5:

Assignment statements such as spam = 10 were added. What's the difference between a declaration and an expression?


Declaration will assign a value to a variable .In this way, value assigned to variable determines the data type of variable.

Expression includes combination of values, operators and assignment.

Question 6:

After running the following code, what does the variable bacon contain?

bacon = 22

bacon + 1


bacon=23 after running the code.

Question 7:

What should the values of the following two terms be?

'spam' + 'spamspam'

'spam' * 3


’spam’+’spamspam’ =’spamspamspam’


Question 8:

Why is it that eggs is a true variable name but 100 is not?


eggs is a true variable name because it can be initialized to any data type and can take any value during the program

while 100 is well defined constant in any language and cannot be used to take data of any other form.

Question 9:

Which of the following three functions may be used to convert a value to an integer, a floating-point number, or a string?


functions not given. However, below can be taken as an explanation

Two types of data type conversion in python

>implicit data type conversion: the type of data changes from one type to another without user involvement.

For example,


print(“the type of “a” is , type(a))


print(“the type of “b” is , type(b))


print(“c is{} and the type of “c” is , c ,type(c))


type of a is int

type of b float

c is 22.6 and the type of c is float->As seen ,the type of “a” changes automatically to float

>explicit data type conversion: the type of data is changed manually in the program

For e.g s=”100001”

x= int(s,2) where 2 is the base to which the string will be converted

print (x)


33->the string converted to base 2

Similarly, float(),hex(), oct() are other form to change data type to respective types.

Question 10:

What is the error caused by this expression? What would you do about it?

'I have eaten ' + 99 + ' burritos.'


The first data is a string constant followed by integer constant and then followed by another string constant. The addition operation performed on two different data types.

As in this case , changing the type of integer constant”99” to string will be more logical

We can use , ‘I have eaten’+’99’+’burritos’ which would give an output as below

‘I have eaten 99 burritos’


bottom of page