Python Octal Numbers and Data Structures Quiz
30 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which Python syntax correctly represents an octal number?

  • 0o123 (correct)
  • 123o
  • 0x123
  • oct(123)

Which of the following is NOT a valid way to define an octal number in Python?

  • 25o (correct)
  • 0O34
  • oct(21)
  • 0o25

What is the decimal equivalent of the octal number 17?

  • 19
  • 17
  • 15 (correct)
  • 23

Given the octal number 12, what is its binary equivalent?

<p>1100 (D)</p> Signup and view all the answers

Which function would you use to convert a decimal number to octal in Python?

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

What is the primary characteristic of the data structure described?

<p>It does not support indexing or slicing. (C)</p> Signup and view all the answers

How are items populated in this data structure?

<p>By simply listing the items enclosed in curly braces. (B)</p> Signup and view all the answers

What happens to the items in this data structure related to uniqueness?

<p>Only the first instance of each item is stored. (A)</p> Signup and view all the answers

How does this data structure treat its elements?

<p>It hashes items to ensure uniqueness. (B)</p> Signup and view all the answers

When defining this data structure, which of the following is true?

<p>It uses commas to separate items without colons. (D)</p> Signup and view all the answers

What does the statement d['Ali'] = 20 represent in the context of a dictionary?

<p>It assigns the key 'Ali' a value of 20 in the dictionary. (A)</p> Signup and view all the answers

Which of the following statements is true regarding dictionary keys?

<p>Dictionary keys must be unique within the same dictionary. (A)</p> Signup and view all the answers

What is the primary characteristic of an empty string in terms of memory usage?

<p>It requires one byte for its termination character. (D)</p> Signup and view all the answers

If d is a dictionary, what will d.get('Ali') return if 'Ali' does not exist in the dictionary?

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

How can you ensure that all keys in a dictionary are of the same data type?

<p>This is not achievable as Python allows mixed types. (A)</p> Signup and view all the answers

What does MRO stand for in the context of class relations?

<p>Method Resolution Order (B)</p> Signup and view all the answers

Which of the following concepts is related to inheritance in programming?

<p>Composition (A), Polymorphism (D)</p> Signup and view all the answers

In programming, what is a characteristic of multiple inheritance?

<p>A class can inherit from multiple parent classes. (A)</p> Signup and view all the answers

Which of the following statements best describes the concept of composition?

<p>It refers to the creation of new classes using existing classes. (A)</p> Signup and view all the answers

What is a potential issue that can arise from multiple inheritance?

<p>Ambiguity in method resolution. (B)</p> Signup and view all the answers

What is the purpose of the append method in programming?

<p>To add an item to the end of a list (B)</p> Signup and view all the answers

How can we generate multiples of 3 between 3 and 999 in Python using one line of code?

<p>list(range(3, 999, 3)) (C)</p> Signup and view all the answers

What is a significant property of the range function in Python?

<p>It returns an iterable that generates numbers on demand (A)</p> Signup and view all the answers

Which of the following descriptions about the range function is incorrect?

<p>It cannot generate negative numbers (A)</p> Signup and view all the answers

Which of the following statements is true regarding range creation?

<p>The function can use a step to skip values (C)</p> Signup and view all the answers

What functionality does the 'in' operator provide in Python?

<p>It determines if an element exists within a collection. (D)</p> Signup and view all the answers

Which of the following correctly describes the syntax for using the 'in' operator?

<p>'element in collection' (D)</p> Signup and view all the answers

What would be the outcome of evaluating 'a in b' if a is 5 and b is a list containing [1, 2, 3]?

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

Which of the following statements is true when using the 'in' operator with strings?

<p>'substring in main_string' returns True if substring is found. (C)</p> Signup and view all the answers

How does the 'in' operator behave when used with dictionaries in Python?

<p>It checks for the presence of keys. (D)</p> Signup and view all the answers

Flashcards

What does the 'in' operator do?

The in operator checks if a specific item exists within a sequence like a list, tuple, or string.

Sequence

A sequence is an ordered collection of elements. Examples include lists, tuples, and strings.

What does the 'in' operator return?

The in operator returns True if the item is found in the sequence and False otherwise.

Why is the 'in' operator useful?

The in operator is a useful way to check if something is contained within a sequence, without having to loop through it.

Signup and view all the flashcards

How do you use the 'in' operator?

To use the in operator, write item in sequence where item is the value you're looking for and sequence is the collection you want to check.

Signup and view all the flashcards

String

A data type used to represent sequences of characters, enclosed within single or double quotes in Python. Examples include "Hello" and 'World'.

Signup and view all the flashcards

Integer

An integer data type in Python that represents whole numbers without decimals. Examples include 10, 25, and -5.

Signup and view all the flashcards

Scientific Notation

A scientific notation in Python to represent very large or small numbers. It uses the base 10 and a power (exponent). Example: 3 * 10^6 represents 3 million.

Signup and view all the flashcards

Octal Number System

A base-8 number system, using digits from 0 to 7. It's represented in Python using the prefix '0o'. Example: 0o10 represents 8 in decimal.

Signup and view all the flashcards

Float

A data type in Python used to represent numerical values with a fractional part. Examples include 3.14, 2.5, and -1.0.

Signup and view all the flashcards

What is a set?

A set is a collection of unique and unordered items. It's created using curly braces {} and populated like a list, without requiring key-value pairs. Sets do not allow duplicates and use hashing for fast lookup.

Signup and view all the flashcards

Can you index or slice sets?

Sets in Python don't support indexing or slicing because they are unordered. You cannot access elements by their position.

Signup and view all the flashcards

When are sets useful?

Sets are useful for removing duplicate entries and efficiently checking if an item exists in the collection.

Signup and view all the flashcards

How do you create and modify sets?

Sets can be created with curly braces {} and elements can be added using the add() method.

Signup and view all the flashcards

What are some use cases for sets?

Sets are often used in situations where you need to check for membership efficiently, find unique elements, or perform operations like union, intersection, or difference between sets.

Signup and view all the flashcards

What is a dictionary in Python?

A dictionary is a data structure in Python that stores key-value pairs. Each key must be unique and immutable (such as strings, numbers, or tuples). The values can be any Python object.

Signup and view all the flashcards

How do you assign values to keys in a dictionary?

In Python, the assignment operator = is used to assign a value to a variable. For dictionaries, you can assign a value to a key like this: dictionary_name[key] = value.

Signup and view all the flashcards

How much space does an empty string take?

An empty string in Python takes up 1 byte of memory space.

Signup and view all the flashcards

Why are dictionary keys unique?

Dictionary keys in Python must be unique. This means you cannot have two keys with the same name within the same dictionary. If you try to assign a value to an existing key it will overwrite the old value

Signup and view all the flashcards

What does d['Ali'] = 20 mean?

The assignment d['Ali'] = 20 in Python means that the dictionary d will store a mapping between the key 'Ali' and the value 20.

Signup and view all the flashcards

range()

The range() function generates a sequence of numbers. It takes three arguments: the start value (inclusive), the stop value (exclusive), and the step value (optional, default is 1). It returns a range object, which can be iterated over to get the numbers.

Signup and view all the flashcards

list()

The list() function converts an iterable (like a range object) into a list. It places each element of the iterable into a new list. This lets you work with the generated numbers as a list.

Signup and view all the flashcards

append()

The append() method adds a new element to the end of an existing list. It modifies the original list, adding the new element to the list's end.

Signup and view all the flashcards

extend()

The extend() method adds multiple elements to the end of an existing list. The items to be added can be a list, tuple, or other iterable. It expands the original list with the new items.

Signup and view all the flashcards

update()

The update() method modifies an existing element in a list. It takes an index and a new value, replacing the old element at the given index with the new value. It modifies the original list.

Signup and view all the flashcards

What is MRO?

Method Resolution Order (MRO) is a rule that Python uses to determine the order in which methods from multiple parent classes are searched for when an attribute or method call is made on an object. It ensures that the most specific method is found first and applied to the object.

Signup and view all the flashcards

Multiple inheritance

Multiple inheritance allows a class to inherit attributes and methods from multiple parent classes. This means a class can have properties and behaviors from multiple sources.

Signup and view all the flashcards

Composition

Composition is a way of combining objects by using instances of other classes as attributes within a class. It provides flexibility and reusability by building complex structures.

Signup and view all the flashcards

Inheritance

Inheritance is a mechanism where a new class (child class) inherits attributes and methods from an existing class (parent class). This allows code reuse and creates a hierarchy of classes.

Signup and view all the flashcards

Inheritance

Inheritance is a mechanism used to create new classes (child classes) based on existing classes (parent classes). It allows the child class to inherit attributes and methods from the parent class, fostering code reusability and establishing a hierarchy of classes.

Signup and view all the flashcards

Study Notes

Bash Commands

  • ls: Lists the contents of a directory.
  • ls -a: Lists all files and directories, including hidden ones.
  • ls -A: Lists all files and directories, excluding hidden ones and the current directory (.) and parent directory (..).
  • pwd: Prints the current working directory.
  • cd: Changes the current working directory.
  • cd <directory>: Changes to the specified directory.
  • cd ..: Changes to the parent directory.
  • cd ~: Changes to the home directory.
  • mkdir <directory>: Creates a new directory.
  • rmdir <directory>: Removes an empty directory.
  • rm <file>: Removes a file.
  • rm -r <directory>: Removes a directory and its contents recursively.
  • cp <source> <destination>: Copies a file or directory.
  • cp -r <source> <destination>: Copies a directory and its contents recursively.
  • mv <source> <destination>: Moves or renames a file or directory.
  • touch <file>: Creates an empty file.
  • wc -l <file>: Counts the number of lines in a file.
  • wc -w <file>: Counts the number of words in a file.
  • wc -c <file>: Counts the number of characters in a file.
  • head -n <number> <file>: Prints the first lines of a file.
  • tail -n <number> <file>: Prints the last lines of a file.
  • sort <file>: Sorts the lines of a file lexicographically.
  • sort -r <file>: Sorts the lines of a file in reverse lexicographical order.
  • sort -k <column> <file> [options]: Sorts the lines of a file based on the specified column.
  • cut -d <delimiter> -f<column_range> <file>: Extracts the specified columns from a file.
  • grep <pattern> <file>: Searches for lines containing a pattern in a file.
  • grep -i <pattern> <file>: Searches for lines containing a pattern in a file, ignoring case.
  • grep -v <pattern> <file>: Searches for lines not containing the pattern in a file.
  • find <directory> -name <pattern>: Searches for files with names matching a pattern in the specified directory and subdirectories.
  • find <directory> -iname <pattern>: Searches for files with names matching a pattern in the specified directory and subdirectories, ignoring case.
  • type <command>: Checks if a command is a built-in command, function, or an external command.
  • type -a <command>: Displays all commands matching the given pattern.
  • compgen -k: Lists all keywords available in bash.
  • man <command>: Displays the manual page for a command.
  • help <command>: Displays the help page for a command.
  • echo <string>: Displays a string to the terminal.
  • echo -n <string>: Displays a string to the terminal without a newline character.
  • chmod <permissions> <file>: Changes the file permissions.
  • chown <user>:<group> <file>: Changes the owner and group of a file.
  • chgrp <group> <file>: Changes the group of a file.
  • assert <condition> [, <message>]: Checks if a condition is true; if not, it raises an exception.
  • !!: Repeats the previous command.
  • >: Redirects standard output to a file (overwrites).
  • &gt;&gt;: Redirects standard output to a file (appends).
  • 2&gt;: Redirects standard error to a file.
  • 2&gt;&gt;: Redirects standard error to a file (appends).
  • &lt;: Redirects standard input from a file.
  • |: Pipes the output of one command as input to another.

Python

  • assert <expression>, <message>: Checks if the expression is true. Raises an AssertionError if not.
  • import <module>: Imports a module
  • dir(<object>): Lists the attributes and methods of an object.
  • help(<object>): Prints the help information about an object.
  • open(<file_path>, <mode>): Opens a file.
  • read(): Reads the entire content of a file into a string.
  • readlines(): Reads all lines of a file into a list of strings.
  • write(<string>): Writes a string to a file.
  • writelines(<list>): Writes multiple strings (from a list) to a file.
  • close(): Closes an open file.
  • zip(<iterable1>, <iterable2>, ...): Creates an iterator that aggregates elements from multiple iterables.
  • enumerate(<iterable>): Creates an iterator that contains (index, value) tuples.
  • math.sqrt(<number>): Calculates the square root of a number.
  • iter(<iterable>): Returns an iterator from an iterable.
  • next(<iterator>): Returns the next item from an iterator.
  • itertools.repeat(<item>, <n>): Creates an iterator that repeats an item times.
  • itertools.product(<iterable1>, <iterable2>,...): Creates an iterator that outputs all ordered combinations of items in multiple iterables.
  • itertools.combinations(<iterable>, <size>): Creates an iterator that outputs all ordered combinations of items in an iterable, without repeating items.
  • itertools.combinations_with_replacement(<iterable>, <size>): Creates an iterator that outputs all ordered combinations of items in an iterable, allowing repeating items.
  • itertools.permutations(<iterable>, <size>): Creates an iterator that outputs all possible ordered sequence of items in an iterable
  • time.perf_counter(): Gets the performance counter time.
  • timeit(<statement>): Calculates execution time of statements

Pandas

  • df.head(): Displays the first few rows of a DataFrame.
  • df.tail(): Displays the last few rows of a DataFrame.
  • df.dtypes: Displays the data types of each column.
  • df.shape: Returns the dimensions of the DataFrame as a tuple (rows, columns).
  • df.size: Returns the total number of elements in the DataFrame.
  • df.info(): Provides a concise summary of the DataFrame.
  • df.describe(): Generates descriptive statistics of numeric columns (count, mean, std, min, 25%, 50%, 75%, max).
  • df.columns: Returns the column labels as a pandas Index object.
  • df.index: Returns the index labels of a dataframe.
  • df.iat(<row>, <column>): Access a single cell by integer location (fastest way to select 1 value).
  • quizgecko.comdf.iloc(<row>, <column>): Access a single cell by integer location (slower than iat for selecting 1 value).quizgecko.com
  • df.loc[:, <column name>]: Selects a whole column by column name.quizgecko.com
  • df.loc(<row_label1>,<column_label2>): Selects whole rows/columns if they have labelquizgecko.coms.
  • df.drop(): Removes rows or columns.
  • df.set_index(): Sets an existing column as the DataFrame index.
  • df.reset_index(): Resets the index to a default integer index.
  • df.sort_values(): Sorts the values of a column.
  • df.sort_index(): Sorts the index values of a DataFrame.
  • df.explode(): Explode a column of list-like items into multiple rows.
  • df.fillna(): Fills missing values in a column.
  • df.query(): Filters rows based on a query string.
  • df.isin(): Filters rows where column values are present in a list (similar to SQL's IN).
  • df.value_counts(): calculates the occurrence of each unique value in a series
  • df.agg(): Applies multiple aggregation methods to columns within a groupby operation.quizgecko.com

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

AllMighty.txt PDF

Description

Test your knowledge on octal numbers and Python dictionaries in this quiz! You will answer questions about the syntax of octal numbers, conversions between number systems, and dictionary characteristics. Perfect for those learning Python programming.

More Like This

Binary and Octal Number Systems
20 questions
Octal Number System in Programming
18 questions
Binary and Number Systems Quiz
25 questions
Use Quizgecko on...
Browser
Browser