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 |
Question: Answer:
What type of programming language is
Python?
An interpreted, high-level, general-purpose
programming language.
Question: Answer:
What is the main advantage of Python's
syntax?
It emphasizes readability and expressiveness.
Question: Answer:
How is a Python script executed? It is executed directly by an interpreter at runtime
without pre-compilation.
Question: Answer:
What is a key feature of Python's
standard library?
It is vast and augmented by a large array of third-
party libraries.
Question: Answer:
Which companies have adopted
Python for their applications?
Google, Uber, Facebook, and Mozilla.
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 |

Question: Answer:

What type of programming language is Python? An interpreted, high-level, general-purpose programming language.

Question: Answer:

What is the main advantage of Python's syntax? It emphasizes readability and expressiveness.

Question: Answer:

How is a Python script executed? It is executed directly by an interpreter at runtime without pre-compilation.

Question: Answer:

What is a key feature of Python's standard library? It is vast and augmented by a large array of third- party libraries.

Question: Answer:

Which companies have adopted Python for their applications? Google, Uber, Facebook, and Mozilla.

What command is used to print a message in Python? The print() function.

Question: Answer:

How do you write a comment in Python? By using the hash symbol (#) before the comment text.

Question: Answer:

What is a documentation string in Python? A multiline comment written with three opening and closing double quotes.

Question: Answer:

How do you create a string that displays 'Hello' five times? Use the code: print('Hello ' * 5).

Question: Answer:

What is the purpose of the sys module in Python? To access command-line arguments passed to the script.

Question: Answer:

What are variables in Python? References to values in memory that do not require pre-declaration of data types.

Question: Answer:

How are strings represented in Python? As arrays of bytes representing unicode characters.

How do you access a substring in Python? By using slicing with the syntax string[start:end].

Question: Answer:

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

Question: Answer:

What is the structure used to create a list in Python? A list is created with comma-separated elements enclosed in square brackets.

Question: Answer:

How do you access the first element of a list named 'fruits'? Use indexing: fruits[0].

Question: Answer:

What happens when you change a value in a list? Lists are mutable, meaning you can change their values.

Question: Answer:

What do comparison operators return? They return Boolean data types, which can be either True or False.

Question: Answer:

What does the 'in' operator do in Python? It tests for membership in a collection.

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

Question: Answer:

What is the difference between a for loop and a while loop? A for loop runs a predetermined number of times, while a while loop runs as long as a condition is satisfied.

Question: Answer:

What does the range function do? It generates a list of numbers based on specified start, stop, and step parameters.

Question: Answer:

What is the purpose of the break statement? To exit a loop based on a condition external to the loop.

Question: Answer:

What is a user-defined function? A function defined by the user to organize code into logical fragments.

Question: Answer:

What is the difference between local and global variables? Local variables are defined inside a function and accessible only there; global variables are defined outside and accessible everywhere.

Question: Answer:

How do you create a dictionary in Python? Use curly braces with key-value pairs, e.g., {'key': 'value'}.