Python Programming Practice Quiz! Exam

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Bscit_it
B
Bscit_it
Community Contributor
Quizzes Created: 6 | Total Attempts: 2,771
Questions: 40 | Attempts: 196

SettingsSettingsSettings
Python Programming Practice Quiz! Exam - Quiz

.


Questions and Answers
  • 1. 

    Is Python case sensitive when dealing with identifiers?

    • A.

      Yes

    • B.

      No

    • C.

      Machine dependent

    • D.

      None of the mentioned

    Correct Answer
    A. Yes
    Explanation
    Python is case sensitive when dealing with identifiers. This means that the uppercase and lowercase letters are considered as distinct characters. For example, variables named "myVariable" and "myvariable" are treated as two different variables in Python. Therefore, it is important to be consistent with the casing of identifiers while coding in Python.

    Rate this question:

  • 2. 

    Which of the following is an invalid variable?

    • A.

      My_string_1

    • B.

      1st_string

    • C.

      Tempstr

    • D.

      _

    Correct Answer
    B. 1st_string
    Explanation
    The variable "1st_string" is invalid because variable names cannot start with a number in most programming languages. Variable names must start with a letter or an underscore.

    Rate this question:

  • 3. 

    All keywords in Python are in?

    • A.

      Lower case

    • B.

      UPPER CASE

    • C.

      Capitalized

    • D.

      None of the mentioned

    Correct Answer
    D. None of the mentioned
    Explanation
    In Python, keywords are reserved words that have predefined meanings and cannot be used as variable names or identifiers. They are always written in lowercase. Therefore, the correct answer is "lower case."

    Rate this question:

  • 4. 

    Which of the following is an invalid statement?

    • A.

      Abc = 1,000,000

    • B.

      a b c = 1000 2000 3000

    • C.

      A,b,c = 1000, 2000, 3000

    • D.

      a_b_c = 1,000,000

    Correct Answer
    B. a b c = 1000 2000 3000
    Explanation
    The statement "a b c = 1000 2000 3000" is an invalid statement because variable names cannot contain spaces.

    Rate this question:

  • 5. 

    Which is the correct operator for power(x^y)?

    • A.

      X^y

    • B.

      X**y

    • C.

      X^^y

    • D.

      None of the mentioned

    Correct Answer
    B. X**y
    Explanation
    The correct operator for power(x^y) is X**y. This is the exponentiation operator in Python, which raises the value of x to the power of y. It is commonly used to perform calculations involving exponentiation. The other options mentioned (X^y and X^^y) are not valid operators for exponentiation in Python.

    Rate this question:

  • 6. 

    Which one of these is floor division?

    • A.

      /

    • B.

      //

    • C.

      %

    • D.

      None of the mentioned

    Correct Answer
    B. //
    Explanation
    The double forward slash (//) is the floor division operator in Python. Floor division returns the largest whole number that is less than or equal to the division of two numbers. It discards the decimal part of the result and only returns the integer value. This is different from the regular division operator (/) which returns a floating-point number. The percent sign (%) is the modulus operator, used to calculate the remainder of a division operation. Therefore, the correct answer is // as it represents floor division.

    Rate this question:

  • 7. 

    What is the answer to this expression, 22 % 3 is?

    • A.

      7

    • B.

      1

    • C.

      0

    • D.

      5

    Correct Answer
    B. 1
    Explanation
    The expression 22 % 3 represents the remainder when 22 is divided by 3. In this case, 22 can be divided by 3 evenly with a remainder of 1. Therefore, the answer to the expression 22 % 3 is 1.

    Rate this question:

  • 8. 

    Which one of the following has the highest precedence in the expression?

    • A.

      Exponential

    • B.

      Addition

    • C.

      Multiplication

    • D.

      Parentheses

    Correct Answer
    D. Parentheses
    Explanation
    Parentheses have the highest precedence in an expression. This means that any operations within parentheses should be performed first before any other operations in the expression. This is because parentheses are used to group certain parts of an expression together, indicating that those operations should be done first. By giving parentheses the highest precedence, it ensures that the operations within them are prioritized and evaluated before any other operations in the expression.

    Rate this question:

  • 9. 

    Following a set of commands are executed in shell, what will be the output?
    1. >>>str="hello"
    2. >>>str[:2]
    3. >>>

    • A.

      He

    • B.

      Lo

    • C.

      Olleh

    • D.

      Hello

    Correct Answer
    A. He
    Explanation
    The output will be "he" because the command "str[:2]" is slicing the string "hello" from index 0 to index 2 (exclusive), which gives us the substring "he".

    Rate this question:

  • 10. 

    Carefully observe the code and give the answer.
    1. def example(a):
    2. a = a + '2'
    3. a = a*2
    4. return a
    5. >>>example("hello")

    • A.

      Indentation Error

    • B.

      Cannot perform mathematical operation on strings

    • C.

      Hello2

    • D.

      Hello2hello2

    Correct Answer
    A. Indentation Error
    Explanation
    The code is missing proper indentation. This results in an indentation error when the code is executed.

    Rate this question:

  • 11. 

    The following is displayed by a print function call:
    1. tom
    2. dick
    3. harry
    Select all of the function calls that result in this output

    • A.

      Print(”’tom \ndick \nharry”’)

    • B.

      Print(”’tomdickharry”’)

    • C.

      Print(‘tom\ndick\nharry’)

    • D.

      print(‘tom dick harry’)

    Correct Answer
    C. Print(‘tom\ndick\nharry’)
    Explanation
    The correct answer is print(‘tomdickharry’). This function call includes line breaks (\n) between each name, resulting in each name being displayed on a separate line.

    Rate this question:

  • 12. 

    What is the average value of the code that is executed below?
    1. >>>grade1 = 80
    2. >>>grade2 = 90
    3. >>>average = (grade1 + grade2) / 2

    • A.

      85

    • B.

      85.1

    • C.

      95

    • D.

      95.1

    Correct Answer
    B. 85.1
    Explanation
    The given code calculates the average value of two grades, grade1 and grade2. It adds the two grades together and then divides the sum by 2. Therefore, the average value is 85.1.

    Rate this question:

  • 13. 

    What is the result of cmp(3, 1)?  

    • A.

      1

    • B.

      0

    • C.

      True

    • D.

      False

    Correct Answer
    A. 1
    Explanation
    The result of cmp(3, 1) is 1 because cmp() is a built-in function in Python that compares two objects and returns -1 if the first object is less than the second, 0 if they are equal, and 1 if the first object is greater than the second. In this case, 3 is greater than 1, so the result is 1.

    Rate this question:

  • 14. 

    What is the type of inf? 

    • A.

      Boolean

    • B.

      Integer

    • C.

      Float

    • D.

      Complex

    Correct Answer
    B. Integer
    Explanation
    The correct answer is integer because "inf" is a common abbreviation for infinity, which is a concept in mathematics. In programming, infinity is often represented as a special value of the data type float or double. However, in this case, the question specifically asks for the "type" of inf, and since inf is not a variable or a specific value, it doesn't have a data type. Therefore, the answer is integer because inf is not a boolean, float, or complex number.

    Rate this question:

  • 15. 

    What is the output of the following?True = False while True: print(True) break

    • A.

      True

    • B.

      False

    • C.

      None

    Correct Answer
    C. None
    Explanation
    The output of the given code is "None". This is because the code assigns the value of False to the variable True, which is not allowed in Python. However, since the code breaks out of the while loop immediately after the first iteration, the print statement is never executed. Therefore, there is no output and the value of the code is None.

    Rate this question:

  • 16. 

     What is the output of the following?x = ['ab', 'cd'] for i in x: i.upper() print(x) 

    • A.

      [‘ab’, ‘cd’].

    • B.

      [‘AB’, ‘CD’].

    • C.

      [None, None].

    • D.

      None of the mentioned

    Correct Answer
    A. [‘ab’, ‘cd’].
    Explanation
    The output of the code is [‘ab’, ‘cd’] because the code is iterating over each element in the list x and applying the upper() method to each element. However, the upper() method returns a new string with all lowercase characters converted to uppercase, but it does not modify the original string. Therefore, the original list x remains unchanged and the output is still [‘ab’, ‘cd’].

    Rate this question:

  • 17. 

     What is the output of the following?x = 'abcd' for i in x: print(i.upper()) 

    • A.

      A b c d

    • B.

      A B C D

    • C.

      a B C D

    • D.

      Error

    Correct Answer
    B. A B C D
    Explanation
    The given code iterates through each character in the string 'abcd' and prints the uppercase version of each character. So, the output will be 'A B C D'.

    Rate this question:

  • 18. 

    What is the output of the following?x = 'abcd' for i in range(len(x)): print(i) 

    • A.

      A b c d

    • B.

      0 1 2 3

    • C.

      Error

    • D.

      1 2 3 4

    Correct Answer
    B. 0 1 2 3
    Explanation
    The output of the given code is 0 1 2 3.

    The code initializes a variable x with the string 'abcd'. It then iterates over the range of the length of x, which is 4 in this case. During each iteration, it prints the value of i, which starts from 0 and goes up to 3. Therefore, the output will be 0 1 2 3, each value on a separate line.

    Rate this question:

  • 19. 

    What is the output of the following?for i in range(2.0): print(i) 

    • A.

      0.0 1.0

    • B.

      0 1

    • C.

      error

    • D.

      None of the mentioned

    Correct Answer
    C. error
    Explanation
    The code will throw an error because the range() function does not accept float values as arguments. The range() function can only accept integer values.

    Rate this question:

  • 20. 

    What is the output when following statement is executed ?
    1. >>>"a"+"bc"
     

    • A.

      A

    • B.

      Bc

    • C.

      Bca

    • D.

      Abc

    Correct Answer
    D. Abc
    Explanation
    The output of the given statement "a" + "bc" is "abc". This is because the "+" operator is used for concatenation in Python, which means it combines two strings together. In this case, the string "a" is combined with the string "bc" to form the resulting string "abc".

    Rate this question:

  • 21. 

    What arithmetic operators cannot be used with strings ? 

    • A.

      +

    • B.

      *

    • C.

      -

    • D.

      All of the mentioned

    Correct Answer
    C. -
    Explanation
    The arithmetic operator "-" cannot be used with strings. This is because the "-" operator is used for subtraction and it does not have any meaning when applied to strings. Strings can be concatenated using the "+" operator, repeated using the "*" operator, but subtraction is not a valid operation for strings.

    Rate this question:

  • 22. 

    What is the output when following code is executed ?
    1. >>> str1 = 'hello'
    2. >>> str1[-1:]

    • A.

      Olleh

    • B.

      Hello

    • C.

      H

    • D.

      O

    Correct Answer
    D. O
    Explanation
    The code is using negative indexing to access the last character of the string "hello". The syntax str1[-1:] means to start from the last character and go until the end of the string. Therefore, the output will be "o", which is the last character of the string "hello".

    Rate this question:

  • 23. 

    What is the output when following statement is executed ?
    1. >>>print('new' 'line')
     

    • A.

      Error

    • B.

      Output equivalent to print ‘new\nline’

    • C.

      Newline

    • D.

      New line

    Correct Answer
    A. Error
    Explanation
    The given statement will output "new line". This is because the print function will print the string 'new' and then move to a new line to print the string 'line'. Therefore, the output will be "new line".

    Rate this question:

  • 24. 

    What is the output when following code is executed ?
    1. >>>str1="helloworld"
    2. >>>str1[::-1]
     

    • A.

      Dlrowolleh

    • B.

      Hello

    • C.

      World

    • D.

      Helloworld

    Correct Answer
    A. Dlrowolleh
    Explanation
    The given code is using slicing with a step value of -1 to reverse the string "helloworld". When a negative step value is used, the slicing starts from the end of the string and goes towards the beginning. So, the output of the code will be "dlrowolleh", which is the reversed version of "helloworld".

    Rate this question:

  • 25. 

    What is the output of the following code ?
    1. >>>example = "snow world"
    2. >>>example[3] = 's'
    3. >>>print example
     

    • A.

      Snow

    • B.

      snow world

    • C.

      Error

    • D.

      Snos world

    Correct Answer
    C. Error
    Explanation
    The code will produce an error. This is because strings in Python are immutable, meaning they cannot be changed once they are created. Therefore, trying to assign a new value to a specific index of a string will result in an error.

    Rate this question:

  • 26. 

    What is the output of the following code ?
    1. >>>example = "snow world"
    2. >>>print("%s" % example[4:7])
     

    • A.

      Wo

    • B.

      World

    • C.

      Sn

    • D.

      Rl

    Correct Answer
    A. Wo
    Explanation
    The code is using string slicing to extract a portion of the "example" string starting from index 4 and ending at index 7 (exclusive). In the "example" string, the characters at index 4, 5, and 6 are "w", "o", and "r" respectively. So, the output will be "wo".

    Rate this question:

  • 27. 

    What is the output of the following code ?
    1. >>>max("what are you")

    • A.

      Error

    • B.

      U

    • C.

      T

    • D.

      Y

    Correct Answer
    D. Y
    Explanation
    The code is attempting to find the maximum value in the string "what are you". However, since the max() function is being used on a string, it will return the character with the highest ASCII value, which in this case is "y".

    Rate this question:

  • 28. 

     Given a string example=”hello” what is the output of example.count(l) 

    • A.

      2

    • B.

      1

    • C.

      None

    • D.

      0

    Correct Answer
    A. 2
    Explanation
    The output of example.count(l) is 2 because the count() method in Python returns the number of occurrences of a specified substring in a string. In this case, "l" appears twice in the string "hello".

    Rate this question:

  • 29. 

     What is the output of the following code ?
    1. >>>example = "helle"
    2. >>>example.find("e")
     

    • A.

      Error

    • B.

      -1

    • C.

      1

    • D.

      0

    Correct Answer
    C. 1
    Explanation
    The output of the code is 1. The find() method in Python returns the index of the first occurrence of the specified substring within the given string. In this case, the substring "e" is found at index 1 in the string "helle". Therefore, the output is 1.

    Rate this question:

  • 30. 

    Which of the following function checks in a string that all characters are whitespaces? 

    • A.

      islower()

    • B.

      Isnumeric()

    • C.

      Isspace()

    • D.

      Istitle()

    Correct Answer
    C. Isspace()
    Explanation
    The function isspace() is used to check whether all characters in a string are whitespaces. It returns True if all characters are whitespaces, otherwise, it returns False. This function is useful when we want to validate if a string contains only spaces or not.

    Rate this question:

  • 31. 

    Which of the following data types is not supported in python?

    • A.

      Tuple

    • B.

      Dictionary

    • C.

      Generics

    • D.

      List

    Correct Answer
    C. Generics
    Explanation
    Generics is not a supported data type in Python. Generics are commonly used in statically typed languages like Java and C# to define classes, interfaces, or methods that can work with different types of data. However, Python is a dynamically typed language, which means that variables can hold values of any type without explicitly specifying the type. Therefore, generics are not necessary in Python and are not supported as a built-in data type.

    Rate this question:

  • 32. 

    Which of the following is correct about Python?

    • A.

      It supports automatic garbage collection.

    • B.

      It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

    • C.

      Both

    Correct Answer
    C. Both
    Explanation
    Python supports automatic garbage collection, which means that the memory management is handled automatically by the language itself. This helps in freeing up memory that is no longer in use, making the programming process more efficient and less prone to memory leaks. Additionally, Python can be easily integrated with various other programming languages and technologies such as C, C++, COM, ActiveX, CORBA, and Java. This allows developers to leverage existing code and libraries in their Python projects, making it a versatile and flexible language for software development.

    Rate this question:

  • 33. 

    Which of the following is correct about Python?

    • A.

      Python is a high-level, interpreted, interactive and object-oriented scripting language.

    • B.

      Python is designed to be highly readable.

    • C.

      It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.

    • D.

      All of the above.

    Correct Answer
    D. All of the above.
    Explanation
    Python is a versatile programming language that is high-level, interpreted, interactive, and object-oriented. It is designed to prioritize readability, using English keywords instead of punctuation and having fewer syntactical constructions compared to other languages. Therefore, all of the statements provided are correct about Python.

    Rate this question:

  • 34. 

     Which of the following expressions is an example of type conversion? 

    • A.

      4.0 + float(3)

    • B.

      5.3 + 6.3

    • C.

      5.0 + 3

    • D.

      3 + 7

    Correct Answer
    A. 4.0 + float(3)
    Explanation
    The expression 4.0 + float(3) is an example of type conversion because the integer 3 is being explicitly converted to a float using the float() function. This allows for the addition of a float (4.0) and an integer (3) by converting the integer to a float before performing the addition operation.

    Rate this question:

  • 35. 

    What is the value of the expression:float(4+int(2.39)%2) 

    • A.

      5.0

    • B.

      5

    • C.

      4.0

    • D.

      4

    Correct Answer
    C. 4.0
    Explanation
    The expression first calculates the value of int(2.39) which is 2. Then it calculates 4 + 2 % 2 which is equal to 4. Finally, the float() function is used to convert the result to a floating-point number, resulting in 4.0.

    Rate this question:

  • 36. 

    Which of the following expressions results in an error?

    • A.

      float(‘10’)

    • B.

      int(‘10’)

    • C.

      Float(’10.8’)

    • D.

      Int(’10.8’)

    Correct Answer
    D. Int(’10.8’)
    Explanation
    The expression int('10.8') results in an error because the int() function is used to convert a value to an integer, but '10.8' is a string that cannot be directly converted to an integer.

    Rate this question:

  • 37. 

    Who created Python?

    • A.

      Guido van Rossam

    • B.

      Bjarne Stroustrup

    • C.

      James Gosling

    • D.

      Dennis Ritchie

    Correct Answer
    A. Guido van Rossam
    Explanation
    Guido van Rossum is the creator of Python. He developed the programming language in the late 1980s and released the first version in 1991. Python was designed to be easy to read and write, with a focus on simplicity and code readability. It has since become one of the most popular programming languages in the world, known for its versatility and extensive libraries.

    Rate this question:

  • 38. 

    Python programs are executed by:

    • A.

      Interpreter

    • B.

      Compiler

    • C.

      Assembler

    Correct Answer
    A. Interpreter
    Explanation
    Python programs are executed by an interpreter. An interpreter is a program that reads and executes code line by line. It translates the code into machine language instructions and immediately executes them. This allows for a more interactive and flexible programming experience, as the interpreter can execute code on the go and provide immediate feedback. In contrast, a compiler translates the entire code into machine language instructions before execution, resulting in a standalone executable file. An assembler, on the other hand, is used for low-level programming languages like assembly language.

    Rate this question:

  • 39. 

    If there is a  ___ error in the program, it will run without generating error messages but it will not give the desired result.

    • A.

      Semantic error

    • B.

      Syntax error

    • C.

      Run-Time error

    Correct Answer
    A. Semantic error
    Explanation
    A semantic error is a type of error in programming where the code is syntactically correct but does not produce the desired result. This means that the program will run without any error messages, but the output or behavior of the program will be incorrect. In other words, there is a logical mistake in the code that leads to incorrect execution. Therefore, if there is a semantic error in the program, it will run without generating error messages but will not give the desired result.

    Rate this question:

  • 40. 

    Which one of the following is used for indexing in the python program?

    • A.

      Brackets [ ]

    • B.

      Parenthesis ( )

    • C.

      Braces { }

    Correct Answer
    A. Brackets [ ]
    Explanation
    Brackets [ ] are used for indexing in a Python program. In Python, indexing is used to access individual elements or a range of elements in a sequence like a string, list, or tuple. By using brackets [ ] with an index value inside, we can retrieve the desired element from the sequence. The index value starts from 0 for the first element, and negative indexing can also be used to access elements from the end of the sequence. Therefore, the correct answer is brackets [ ].

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 01, 2017
    Quiz Created by
    Bscit_it

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.