Fundamentals of Python Programming Flashcards
5 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 5 Fundamentals of Python Programming flashcards as text
Which of the following is the correct syntax to output "Hello, World!" in Python?
Answer: print("Hello, World!")
In Python, the `print()` function is the standard way to display output to the console. To output a string like "Hello, World!", you pass the string as an argument inside the parentheses of the `print()` function, enclosed in either single or double quotes. This syntax is universally used for producing console output in Python programs.
Which data type is used to store textual data in Python?
Answer: str
In Python, the `str` data type (short for string) is specifically designed to store textual data, which consists of sequences of characters. Strings are immutable, meaning their content cannot be changed after creation. This data type is fundamental for handling any text-based information, such as names, messages, or file paths, within Python programs.
Which of the following is used to start a comment in Python?
Answer: #
In Python, the hash symbol `#` is used to denote a single-line comment. Any text following `#` on that line is ignored by the Python interpreter and serves as documentation for human readers. This allows programmers to add explanatory notes, clarify complex logic, or temporarily disable code sections without affecting program execution.
Which of the following Python expressions correctly calculates the length of a string?
Answer: len(string)
Python provides the built-in `len()` function to determine the number of items in an object. When applied to a string, `len(string)` returns the total count of characters within that string. This is the standard and most direct way to get a string's length, which is crucial for various string manipulation tasks.
Which of the following statements correctly initializes a dictionary in Python?
Answer: dict = { 'name': 'Alice', 'age': 25 }
In Python, dictionaries are created using curly braces `{}` and store data as key-value pairs. Each key is separated from its value by a colon `:`, and pairs are separated by commas. The syntax `dict = { 'name': 'Alice', 'age': 25 }` correctly initializes a dictionary named `dict` with two key-value entries, making it ready for use.