Programming and Problem Solving Through Python Language Theory Question
Introduction to Python - Set 4
Which of folowing are valid escape sequnces in python ?
\n
\t
\\
All of above
Answer : D
Explain : \n is for new line, \t is for horizontal tab, \\ use for blackslash.
Why are local variable names beginning with an underscore discouraged ?
They confuse the interpreter
they are used to indicate a private variables class
they slown down execution
they are used to indicate global variables
Answer : B
Explain : Leading Underscore before variable/function /method name indicates to the programmer that it is for internal use only, that can be modified whenever the class wants.
Which of the following is an invalid statement?
abc = 100
a_b_c =100
a,b,c = 10,20,20
a b c = 10 20 30
Answer : D
Explain : Space is not allowed when we decalre variable names.
What will be the output of following code ?
if 2+5==8:
print('TRUE')
else:
print("FALSE")
print('TRUE')
TRUE
TRUE FALSE
FALSE TRUE
FALSE FALSE
Answer : C
Explain : Do it your own.
Which of these is not a core data type ?
List
Tuple
Dictionary
Class
Answer : D
Explain : Class is user defined data type.
In python, variable name is number. So which type of data it store?
Integer
String
float
All of the above
Answer : D
Explain : We can decalare variable name any except keyword and store any data type in it. So, in question variable name is given no the value.
Which of the following variable declaration is incorrect ?
_a=3
a_=3
a?=3
All of these
Answer : C
Explain : While declare varaible we cannot use special charachters like !, @, #, $, % etc.
What is the maximum possible length of an identifier ?
16
32
64
None of these
Answer : D
Explain : Identifiers can be declare of any length.
Which of the following is not a valid identifier?
student
s12
123
_123
Answer : C
Explain : In Python, variable name cannot start with numeric value.
Which symbol is used to write single line comment ?
/
*
#
$
Answer : C
Explain : In Python, we use the hash symbol # to write a single-line comment.