Python Programming Language Trivia Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By 96redformy
9
96redformy
Community Contributor
Quizzes Created: 1 | Total Attempts: 802
| Attempts: 802 | Questions: 28
Please wait...
Question 1 / 28
0 %
0/100
Score 0/100
1. Which two operators can be used on numeric values in Python?

Explanation

The % operator is used for modulus, which returns the remainder of a division operation. The + operator is used for addition, which adds two or more numeric values together. These two operators are commonly used in Python for performing mathematical operations on numeric values.

Submit
Please wait...
About This Quiz
Python Programming Language Trivia Quiz - Quiz

The Python programming language trivia Quiz tests knowledge on syntax and functionalities of Python. It includes questions on string formats, print statements, and variable assignments, essential for beginners... see moreand intermediate programmers to validate their coding skills. see less

2. Which symbol is used to check whether two variables are the same?

Explanation

The symbol "==" is used to check whether two variables are the same. It is an equality operator that compares the values of the two variables and returns true if they are equal, and false otherwise.

Submit
3. True or False: A variable is a placeholder for data.

Explanation

A variable is a placeholder for data because it is used to store and represent different values or information within a program. It can hold various types of data such as numbers, text, or objects, and its value can be changed throughout the execution of the program. By using variables, programmers can manipulate and work with data in a flexible and dynamic way. Therefore, it is correct to say that a variable acts as a placeholder for data.

Submit
4. A shorter option for an "else if" statement is:

Explanation

The correct answer is "elif" because it is a shorter way to write "else if" in programming. It is used as a conditional statement to check for multiple conditions after an initial "if" statement. The "elif" statement allows for more concise and readable code by avoiding nested if statements.

Submit
5.  You have the following code segment: testValue = 2 testValue = 10 + (testValue * 2) What is the value of testValue?

Explanation

The code segment initializes the variable testValue with the value 2. Then, it assigns the result of the expression 10 + (testValue * 2) to testValue. Since testValue is currently 2, the expression evaluates to 10 + (2 * 2) = 10 + 4 = 14. Therefore, the value of testValue is 14.

Submit
6. What is the output of this code? >>> print(3 * 'TCS') ANS = '_______'  

Explanation

The code is using the multiplication operator (*) to repeat the string 'TCS' three times. Therefore, the output of the code will be 'TCSTCSTCS'.

Submit
7. You have the following code segment: myString = "hello world" print( myString.upper() + " " + myString ) What is the output of this code?

Explanation

The code segment converts the string "hello world" to uppercase using the `.upper()` method and then concatenates it with a space and the original string. Therefore, the output of this code would be "HELLO WORLD hello world".

Submit
8. Which two lines of code are valid strings in Python?  

Explanation

The two valid strings in Python are 'This is a string' and "This is a string". In Python, strings can be represented using either single quotes or double quotes.

Submit
9. True or False: Variables can be assigned only once.

Explanation

Variables can be assigned multiple times in programming. Once a variable is declared, its value can be changed or updated throughout the program. This allows for flexibility and the ability to store and manipulate different values as needed. Therefore, the statement "Variables can be assigned only once" is false.

Submit
10. You have the following code segment: print("Here we have a line of text \n and \n we can do newlines!") What is the output of this code?

Explanation

The output of this code will be "Here we have a line of text \n and \n we can do newlines!". This is because the "\n" character is used to represent a newline in Python, so when the code is executed, it will print the text with the newlines intact.

Submit
11. True or False: A string can be surrounded by three sets of single quotation marks or by three sets of double quotation marks.

Explanation

A string can indeed be surrounded by three sets of single quotation marks or by three sets of double quotation marks. This is known as triple quoting and can be used in some programming languages to represent multi-line strings. It provides a convenient way to include special characters, line breaks, and formatting within the string without the need for escape sequences.

Submit
12. You have the following code segment: myString01 = "my" myString02 = "string" print(myString01 + myString02) What is the output of this code?

Explanation

The code segment concatenates the values of myString01 and myString02 using the + operator. The value of myString01 is "my" and the value of myString02 is "string". Therefore, the output of the code is "mystring".

Submit
13. You have the following code segment: currentAmount = 100 itemCost = 100 if currentAmount >= itemCost :     print("Item Purchased") else :     print("Not Enough Funds") What is the output from this code?

Explanation

The output from this code will be "Item Purchased". This is because the condition in the if statement is true, as the currentAmount is equal to the itemCost. Therefore, the code inside the if block will be executed, which is to print "Item Purchased".

Submit
14. Which line of code produces an error?

Explanation

The line of code '5' + 6 produces an error because it is trying to concatenate a string ('5') with a number (6). In most programming languages, concatenating a string with a number is not allowed and results in a type mismatch error.

Submit
15. What is the result of this code? if 1 + 1 * 3 == 6:    print("Yes") else:    print("No")

Explanation

The result of this code is "No". This is because the condition in the if statement is false. The expression 1 + 1 * 3 evaluates to 4, not 6. Therefore, the code will execute the else block and print "No".

Submit
16. Which code segment will NOT reach its print() function?

Explanation

The code segment "if 'yes' != 'yes' : print("condition met")" will not reach its print() function because the condition 'yes' != 'yes' is False, so the code block inside the if statement will not be executed.

Submit
17. Which value type does input() return?

Explanation

The input() function in Python returns a string value. This means that whenever we use the input() function to get user input, the value returned will be in the form of a string. If we want to use this input as an integer or a float, we need to explicitly convert it using the int() or float() functions, respectively.

Submit
18. Which line of code has the proper syntax for the print statement?

Explanation

The line of code "print( ‘it\’s a rainy day’ )" has the proper syntax for the print statement because it uses single quotes to enclose the string and escapes the apostrophe within the string using a backslash.

Submit
19. True or False: You can combine a numeric value and a string by using the + symbol. 

Explanation

The + symbol in programming is used for concatenation, which is the process of combining two strings together. It is not used to combine a numeric value and a string. To combine a numeric value and a string, you would need to convert the numeric value to a string first and then concatenate them. Therefore, the statement is false.

Submit
20. Which two sections of code print 'Hello World' to the console?

Explanation

The two sections of code that print 'Hello World' to the console are:
1. myValue = "Hello World"
if myValue == "Hello World":
print("Hello World")
This section checks if myValue is equal to "Hello World" and if it is, it prints "Hello World" to the console.

2. myValue = "Hello World"
if myValue == "Hello World":
print(myValue)
This section also checks if myValue is equal to "Hello World" and if it is, it prints the value of myValue, which is "Hello World", to the console.

Submit
21. You have the following code segment: myValue = "yes" if myValue != "yes" :     print("Hello") print("World") What is the output from this code?

Explanation

The output from this code is "World". The code assigns the value "yes" to the variable myValue. The if statement checks if myValue is not equal to "yes", which is false. Therefore, the print("Hello") statement is not executed. Finally, the print("World") statement is executed, resulting in the output "World".

Submit
22. What is the output of this code? >>> int("3" + "4")

Explanation

The code is concatenating the strings "3" and "4" using the + operator. Then, it is converting the resulting string "34" into an integer using the int() function. The int() function converts a string representation of a number into an actual integer. Therefore, the output of the code is the integer 34.

Submit
23. What is the output of this code? num = 7 if num > 3:    print("3")    if num < 5:       print("5")       if num ==7:         print("7")  

Explanation

The output of this code is "3". This is because the condition "num > 3" is true, so the code inside the if statement is executed. The next if statement "num

Submit
24. You have the following code segment: myString01 = "my" myString02 = "string" print(myString01 , myString02) What is the output of this code?

Explanation

The code segment declares two variables, myString01 and myString02, and assigns them the values "my" and "string" respectively. Then, it prints the values of both variables separated by a space. Therefore, the output of this code will be "my string".

Submit
25. Which two code segments output the number 20 to the console window?

Explanation

The first code segment assigns the value "10" to myValue01 and myValue02, then concatenates them and assigns the result to myValue01. Finally, it prints the value of myValue01, which is 20. The second code segment assigns the value 10 to myValue01 and myValue02, then adds them together and prints the result, which is also 20.

Submit
26. Which line of code will cause an error? num = [5, 4, 3, [2], 1] print(num[0]) print(num[3][0]) print(num[5])

Explanation

Line 4 will cause an error because the index 5 is out of range for the list "num". The list "num" only has indices from 0 to 4.

Submit
27. What is the output of this code? >>> float("210" * int(input("Enter a number:" ))) Enter a number: 2

Explanation

The code first prompts the user to enter a number, which is then converted to an integer. The string "210" is then multiplied by this integer. The resulting string "210210" is then converted to a float, resulting in the output of "210210.0".

Submit
28. Given the numeric variable myNumber, which lines of code properly prints the value? (Select 2)

Explanation

The correct answer is "print(myNumber)" and "print("%d" % myNumber)". The first option prints the value of the variable directly, while the second option uses string formatting to insert the value of the variable into the string before printing it.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 24, 2018
    Quiz Created by
    96redformy
Cancel
  • All
    All (28)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which two operators can be used on numeric values in Python?
Which symbol is used to check whether two variables are the same?
True or False: A variable is a placeholder for data.
A shorter option for an "else if" statement is:
 You have the following code segment: ...
What is the output of this code? ...
You have the following code segment: ...
Which two lines of code are valid strings in Python?  
True or False: Variables can be assigned only once.
You have the following code segment: ...
True or False: A string can be surrounded by three sets of single...
You have the following code segment: ...
You have the following code segment: ...
Which line of code produces an error?
What is the result of this code? ...
Which code segment will NOT reach its print() function?
Which value type does input() return?
Which line of code has the proper syntax for the print statement?
True or False: You can combine a numeric value and a string by using...
Which two sections of code print 'Hello World' to the console?
You have the following code segment: ...
What is the output of this code? ...
What is the output of this code? ...
You have the following code segment: ...
Which two code segments output the number 20 to the console window?
Which line of code will cause an error? ...
What is the output of this code? ...
Given the numeric variable myNumber, which lines of code properly...
Alert!

Advertisement