Maximize your CompTIA PenTest+ exam preparation with our specialized quiz. Use flashcards and multiple-choice questions, complete with hints and explanations, to enhance your study sessions and excel in your exam!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


In which programming language is the following if statement written: "if my_var == 1: print 'Correct.'"?

  1. Java

  2. C++

  3. Python

  4. Ruby

The correct answer is: Python

The given if statement is written in Python. This is evident from several key characteristics of the syntax. In Python, the condition of the if statement is followed by a colon, which denotes the start of the subsequent block of code. Additionally, the print function in Python uses a space to separate the function from its arguments; in the example provided, it is formatted as `print 'Correct.'`, which aligns with Python 2 syntax. It is important to note that in Python 3, the correct syntax would be `print('Correct.')`. The other programming languages listed have different syntax conventions for their if statements. For instance, Java and C++ require parentheses around the condition and use curly braces to define code blocks, while Ruby, although having a more similar style to Python, uses "then" or a different format for print statements. Thus, recognizing these syntactical differences reinforces the conclusion that the correct answer is Python.