You are on page 1of 2

Chapter 4:

BASIC DATA TYPES


Questions
1.

a=4
b='string'
print a+b
what is the error in the above program? Please correct the error.
2. Find out the output and its type of the following statements.
int(5.0)
float(5)
str(7)
int("")
str(7.0)
float("5.0")
int("five")
3. Write a program to check a character in a string.
Note: Take a string of your wish.
4. Consider you have 22 apples,20 bananas,30 carrots. Create variables for each fruit and print
the output as follows,
I have 22 apples 20 bananas 30 carrots.
Note:In place of number use the variable.
5. Answer the following questions.
a) Which function used for the address of a variable?
b) Which function used to know whether a given variable is keyword?
c) Which function used to convert object into an expression string?
d) Which function used to find maximum size that integer can take?

Answers:
1.
cannot concatenate string with integer.
print str(a)+b
2.
Ans :
5
integer
5.0 floating point
7
string
error (invalid literal for int)
7.0 string
5.0 float
error
3.
#!/usr/bin/python
x="python"
ch='t'
print ch in x

Note: Output will be 'True' if character found otherwise 'False'


4.
#!/usr/bin/python
apple=22
banana=20
carrot=30
print "I have "+str(apple)+" apples "+str(banana)+" bananas "+str(carrot)+" carrots."
5.
a)
b)
c)
d)

id(variablename)
keyword.iskeyword(name)
repr(word)
sys.maxint

You might also like