Python single-line comments

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Question : Which symbol is used to start a single-line comment in Python?

  • a) //
  • b) –
  • c) # (correct)
  • d) '''

Which of the following is not a reserved keyword in Python?

  • c)else
  • d)elif
  • a)If
  • b)then (correct)

What kind of error happens when there's an indentation mismatch in Python?

  • b) IndentationError (correct)
  • d) ValueError
  • a) SyntaxError
  • c) RuntimeError

For which of the following reason you use comments in Python?

<p>c) Providing additional information and explanations to the reader (C)</p>
Signup and view all the answers

Question: Which of the following methods is not a valid way to execute your Python script?

<p>c) Using a web browser (C)</p>
Signup and view all the answers

Question: How you can exit from a loop prematurely in Python.

<p>A) Using the break statement (A)</p>
Signup and view all the answers

Which keyword is used for making decisions in Python?

<p>C) if (C)</p>
Signup and view all the answers

: Explain how string concatenation is performed in Python. Which operator is used for concatenating strings?

<p>b) + (B)</p>
Signup and view all the answers

What is the output of the expression 10 > 5 in Python?

<p>True (A)</p>
Signup and view all the answers

Which looping statement is used in Python to repeatedly execute a block of code as long as a condition remains true?

<p>B) while loop (B)</p>
Signup and view all the answers

How do you create a histogram in Matplotlib?

<p>a) plt.hist() (A)</p>
Signup and view all the answers

How can you access a specific column named 'column_name' in a DataFrame df?

<p>c) df['column_name'] (C)</p>
Signup and view all the answers

How do you create a DataFrame from a dictionary data in Pandas?

<p>a) pd.DataFrame(data) (A)</p>
Signup and view all the answers

How do you import Matplotlib in Python?

<p>b) import matplotlib.pyplot as plt (B)</p>
Signup and view all the answers

How do you access a function named "my_function" from an imported module named "my_module"?

<p>B) my_module.my_function (B)</p>
Signup and view all the answers

Which python library would you use to efficiently compute the mean?

<p>a) NumPy (A)</p>
Signup and view all the answers

Which NumPy function would you use to calculate the mean value?

<p>np.mean() (A)</p>
Signup and view all the answers

Which Python library would you use to calculate the median efficiently?

<p>a) NumPy (A)</p>
Signup and view all the answers

How would you determine the median if the total number of values in the dataset is even?

<p>A) The average of the two middle values. (A)</p>
Signup and view all the answers

Which statistical measure would help you to determine the most frequently occurring value in the dataset?

<p>C) Mode (C)</p>
Signup and view all the answers

How would you execute a query using PyMySQL?

<p>c) execute() (C)</p>
Signup and view all the answers

What method would you use to retrieve all rows from a result set when working with PyMySQL?

<p>b) fetch_all() (B)</p>
Signup and view all the answers

What method would you use to commit changes to the database in PyMySQL?

<p>Commit (A)</p>
Signup and view all the answers

How do you close a cursor object in PyMySQL?

<p>a)close() (A)</p>
Signup and view all the answers

Which method would you use to undo changes in the database using PyMySQL?

<p>a) rollback() (A)</p>
Signup and view all the answers

Flashcards

Which command is used to execute a Python script?

python script.py

What happens when you execute a Python script in immediate mode?

Answer: The script is executed line by line, and the results are displayed immediately

: You are writing a Python program and accidentally use a reserved keyword, like for, as a variable name. What will happen when you try to run the code?

Python will raise a SyntaxError because reserved keywords cannot be used as variable names.

Why is it important to avoid using reserved keywords, such as if or while, as variable names?

Reserved keywords have predefined meanings in Python, so using them as variable names would cause confusion and break the syntax.

Signup and view all the flashcards

You are starting a new project in Python and need to write code that is both easy to maintain and collaborate on. How does Python's primary design philosophy help you achieve this goal?

Answer: Python’s philosophy prioritizes simplicity and readability, making the code clean and easy for others to maintain and collaborate on.

Signup and view all the flashcards

What is the data type of the variable x in Python if x = 5?

The data type of the variable x in Python if x = 5 is int (integer).

Signup and view all the flashcards

Identify the data type of the result of the expression "Hello" + "World" in Python

The data type of the result of the expression "Hello" + "World" is str (string).

Signup and view all the flashcards

8 List the possible data types and identify the type of the result of 10 > 5 in Python.

Possible data types in Python include int, float, str, bool, list, tuple, dict, set, etc. The type of the result of 10 > 5 is bool (boolean), as it evaluates to True.

Signup and view all the flashcards

What is the function in Python used to determine the length of a string?

The function used to determine the length of a string in Python is len().

Signup and view all the flashcards

Which method in Python is used to convert a string to uppercase?

The method used to convert a string to uppercase in Python is .upper().

Signup and view all the flashcards

: How would you generate random numbers using NumPy

np.random()

Signup and view all the flashcards

What would you use as the best Python library for working with DataFrames?

Pandas

Signup and view all the flashcards

How would you display the initial records of a DataFrame?

head()

Signup and view all the flashcards

Which Matplotlib function would you use to create a basic line plot?

plt.plot()

Signup and view all the flashcards

How would you add grid lines to a Matplotlib line chart?

plt.grid()

Signup and view all the flashcards

Which Python function would you use to find the mode of the dataset?

: mode

Signup and view all the flashcards

You are analyzing customer feedback ratings for a product, and the ratings given by customers are [12, 15, 17, 20, 17, 25, 17]. To determine the most common rating, which value represents the mode of this dataset?

Answer: 17

Signup and view all the flashcards

Which NumPy function would you use to calculate the standard deviation of the dataset?

Answer: std()

Signup and view all the flashcards

Which NumPy function would you use to calculate the variance of the dataset?

Answer: var()

Signup and view all the flashcards

Which keyword in Python would you use to define a class?

Answer: class

Signup and view all the flashcards

What would you expect to happen if there is a connection error in PyMySQL?

Answer: MySQLConnectionError

Signup and view all the flashcards

What would you do with insert_one() method in PyMongo ?

Answer : Inserts a single document into the collection

Signup and view all the flashcards

How would you connect to a MongoDB server using PyMongo?

Answer : MongoClient()

Signup and view all the flashcards

What would you use to install PyMongo, the Python driver for MongoDB?

Answer : pip install pymongo

Signup and view all the flashcards

How would you close a connection to the MySQL database in PyMySQL?

Answer : Using the close() method on the connection object

Signup and view all the flashcards

More Like This

Use Quizgecko on...
Browser
Browser