Programming and Problem Solving Through Python Language Theory Question

Introduction to Python - Set 4

  1. Which of folowing are valid escape sequnces in python ?
    1. \n
    2. \t
    3. \\
    4. All of above
    Answer : D
    Explain : \n is for new line, \t is for horizontal tab, \\ use for blackslash.
  2. Why are local variable names beginning with an underscore discouraged ?
    1. They confuse the interpreter
    2. they are used to indicate a private variables class
    3. they slown down execution
    4. 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.
  3. Which of the following is an invalid statement?
    1. abc = 100
    2. a_b_c =100
    3. a,b,c = 10,20,20
    4. a b c = 10 20 30
    Answer : D
    Explain : Space is not allowed when we decalre variable names.
  4. What will be the output of following code ?
    if 2+5==8:
        print('TRUE')
    else:
        print("FALSE")
    print('TRUE')
    
    
    1. TRUE
    2. TRUE FALSE
    3. FALSE TRUE
    4. FALSE FALSE
    Answer : C
    Explain : Do it your own.
  5. Which of these is not a core data type ?
    1. List
    2. Tuple
    3. Dictionary
    4. Class
    Answer : D
    Explain : Class is user defined data type.
  6. In python, variable name is number. So which type of data it store?
    1. Integer
    2. String
    3. float
    4. 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.
  7. Which of the following variable declaration is incorrect ?
    1. _a=3
    2. a_=3
    3. a?=3
    4. All of these
    Answer : C
    Explain : While declare varaible we cannot use special charachters like !, @, #, $, % etc.
  8. What is the maximum possible length of an identifier ?
    1. 16
    2. 32
    3. 64
    4. None of these
    Answer : D
    Explain : Identifiers can be declare of any length.
  9. Which of the following is not a valid identifier?
    1. student
    2. s12
    3. 123
    4. _123
    Answer : C
    Explain : In Python, variable name cannot start with numeric value.
  10. Which symbol is used to write single line comment ?
    1. /
    2. *
    3. #
    4. $
    Answer : C
    Explain : In Python, we use the hash symbol # to write a single-line comment.

Next Set

1 2 3