Python QA
Python QA
1. What are tokens in python? How many types of tokens are allowed in python?
Exemplify your answer.
Types of tokens,
X=Y=7?
X is a variable and their value is 7 and Y is also variable and their value is 7.
Indentation is one of the most important features of python, indentation is use to mark
blocks of code. It is required for indicating what block of code a statement belongs to.
8. Can nongraphic characters be used in python? How? Give examples to support your
answer.
Yes, non graphic character can be used in python. in python we can use by type in
side of double quote or single quote. Eg. print(“\\”)
Ans:
Output:
3j
1+4.5j
a) y=x+5
print(x,y)
# x is not defined
b) print(x = y = 5)
# Variables are being assigned at the same time as being printed, this is invalid.
c) a= input(“value”)
b=a/2
print(a,b)
# a is a string type because all inputs are taken as string in python and hence a
can’t be divided.
13. From the following, find out which assignment statement will produce an error. State
reason(s) too.
ii) a = 30
b = a + b # b is not defined
print(a And b) # And should be written as and
iii) a, b, c = 2, 8, 9
print(a, b, c)
c, b, a = a, b, c
print(a;b;c) # ',' should be used instead of ';'
iv) X = 24
4 = X # Incorrect assignment, Variables are Rvalues
v) print("X="X) # A ',' should be used between the string and variable
vi) else = 21-5 # else is a keyword and can't be used a variable
b)
>>>type(int(0))
# output
int
c)
>>>type(int('0'))
# output
int
d)
>>>type('0')
# output
str
e)
>>>type(1.0)
# output
float
f)
>>>type(int(1.0))
# output
int
g)
>>>type(float(0))
# output
float
h)
>>>type(float(1.0))
# output
float
i)
>>>type(3/2)
# output
float