Docsity

Introduction to Python: Programming Basics, Data Types, and Control Structures | Objective, Exams of Computer Programming

Toggle sidebar
bg1
A+
Introduction to Python: Programming
Basics, Data Types, and Control Structures
| Objective Assessment | Questions and
Answers with Verified Solutions | Latest
Update
Question:
What type of programming language is Python?
Answer:
An interpreted, high-level, general-purpose programming language.
Question:
What is the main advantage of Python's syntax?
Answer:
It emphasizes readability and expressiveness.
Question:
How is a Python script executed?
It is executed directly by an interpreter at runtime
Answer:
without pre-compilation.
Question:
What is a key feature of Python's standard library?
Answer:
It is vast and augmented by a large array of third- party libraries.
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Python: Programming Basics, Data Types, and Control Structures | Objective and more Exams Computer Programming in PDF only on Docsity!

A+

Introduction to Python: Programming

Basics, Data Types, and Control Structures

| Objective Assessment | Questions and

Answers with Verified Solutions | Latest

Update

Question:

What type of programming language is Python?

Answer:

An interpreted, high-level, general-purpose programming language.

Question:

What is the main advantage of Python's syntax?

Answer:

It emphasizes readability and expressiveness.

Question:

How is a Python script executed? It is executed directly by an interpreter at runtime

Answer:

without pre-compilation.

Question:

What is a key feature of Python's standard library?

Answer:

It is vast and augmented by a large array of third- party libraries.

Which companies have adopted Python for their applications?

Answer:

Google, Uber, Facebook, and Mozilla.

Question:

What command is used to print a message in Python?

Answer:

The print() function.

Question:

How do you write a comment in Python?

Answer:

By using the hash symbol (#) before the comment text.

Question:

What is a documentation string in Python?

Answer:

A multiline comment written with three opening and closing double quotes.

Question:

How do you create a string that displays 'Hello' five times?

Answer:

Use the code: print('Hello ' * 5).

Question:

What is the purpose of the sys module in Python?

Answer:

To access command-line arguments passed to the script.

What prefix is used for binary numbers in Python?

Answer:

0b.

Question:

How do you convert a decimal number to binary in Python?

Answer:

Using the built-in bin() function.

Question:

What operator is used for string concatenation in Python?

Answer:

The + operator.

Question:

What is the index of the first character in a Python string?

Answer:

Question:

How do you access a substring in Python?

Answer:

By using slicing with the syntax string[start:end].

Question:

What are lists in Python? An aggregate data type composed of other data

Answer:

types.

What is the structure used to create a list in Python?

Answer:

A list is created with comma-separated elements enclosed in square brackets.

Question:

How do you access the first element of a list named 'fruits'?

Answer:

Use indexing: fruits[0].

Question:

What happens when you change a value in a list?

Answer:

Lists are mutable, meaning you can change their values.

Question:

What do comparison operators return?

Answer:

They return Boolean data types, which can be either True or False.

Question:

What does the 'in' operator do in Python?

Answer:

It tests for membership in a collection.

Question:

What is a control statement? A structure in code that conditionally changes the

Answer:

program flow.

What method retrieves both keys and values from a dictionary?

Answer:

The items() method.

Question:

What is a set in Python? An unordered collection of unique elements.

Question:

How do you eliminate duplicate entries in a collection?

Answer:

By using a set, which automatically removes duplicates.

Question:

What does the len() function return when applied to a list?

Answer:

It returns the number of items in the list.

Question:

What is the syntax to define a function in Python?

Answer:

def function_name(parameter_one, parameter_two):

Question:

What does the continue statement do in a loop?

Answer:

It skips the current iteration and continues with the next iteration of the loop.

Question:

How can you check if a key exists in a dictionary?

Answer:

Using the syntax 'key in dictionary'.