1. Home
  2. Explore
  3. Computer Science
  4. Python Programming Tutorial

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Python Programming Tutorial

  • 70Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python Foundations

What does it mean that Python is a general-purpose programming language?

70 questions

  1. 1

    What does it mean that Python is a general-purpose programming language?

    1. A

      It is designed only for applications that use the web

    2. B

      It is designed only for programs that analyze numerical data

    3. C

      It is designed for software across many application domains

    4. D

      It is designed for one specific type of hardware

    Correct answer
    C

    It is designed for software across many application domains

    Explanation

    A general-purpose language can be used to write software in varied domains rather than being restricted to one domain.

  2. 2

    Which description best captures Python as a high-level language?

    1. A

      It requires programmers to manage all memory allocation and management themselves

    2. B

      It can run only after being converted manually into a hardware-specific executable

    3. C

      Its syntax consists only of machine instructions that programmers must write directly

    4. D

      Its syntax uses readable, natural-language-like elements and handles some computing tasks automatically

    Correct answer
    D

    Its syntax uses readable, natural-language-like elements and handles some computing tasks automatically

    Explanation

    The tutorial describes high-level languages as easier to read and understand, and says they automate some computing tasks, including memory allocation and management.

  3. 3

    What is the key distinction of an interpreted language as presented in the tutorial?

    1. A

      The script is executed in the same format in which it was created, rather than first being saved as a machine-specific executable

    2. B

      The programmer must declare every variable's type before running the script

    3. C

      The script can contain only instructions written in machine code

    4. D

      The script must be rewritten for each operating system before it can be executed

    Correct answer
    A

    The script is executed in the same format in which it was created, rather than first being saved as a machine-specific executable

    Explanation

    The tutorial contrasts interpreted code with code that is first translated into machine-specific instructions and saved as an executable.

  4. 4

    What does it mean that Python is dynamically typed?

    1. A

      Python infers a variable's type from the value assigned to it

    2. B

      A variable's type is determined by the computer's operating system

    3. C

      Python requires the programmer to declare every variable's type in advance

    4. D

      All variables are treated as strings until explicitly converted

    Correct answer
    A

    Python infers a variable's type from the value assigned to it

    Explanation

    In a dynamically typed language, Python's parser identifies the type based on the data assigned to a variable.

  5. 5

    A variable is assigned a string and later assigned an integer. Which idea from the tutorial explains why this does not inherently cause a type-declaration error?

    1. A

      Python permits reassignment only when both values have the same type

    2. B

      Python uses a separate variable type for each assignment automatically

    3. C

      Python converts every assigned value into a string

    4. D

      Python determines the type from the value assigned, rather than requiring a prior type declaration

    Correct answer
    D

    Python determines the type from the value assigned, rather than requiring a prior type declaration

    Explanation

    The tutorial connects dynamic typing with inferring a variable's type from its assigned value and not requiring an explicit type declaration.

  6. 6

    Who is identified in the tutorial as the creator of Python?

    1. A

      Guido van Rossum

    2. B

      Dennis Ritchie

    3. C

      Bjarne Stroustrup

    4. D

      James Gosling

    Correct answer
    A

    Guido van Rossum

    Explanation

    The tutorial identifies Guido van Rossum as the creator of Python.

  7. 7

    What does it mean that Python is open source, according to the tutorial?

    1. A

      Only the original creator can inspect or change its source code

    2. B

      The language can be used only for noncommercial software

    3. C

      The public can download, use, modify, and distribute its source code

    4. D

      Its source code is available only after a paid license is purchased

    Correct answer
    C

    The public can download, use, modify, and distribute its source code

    Explanation

    The tutorial describes open-source code as available to the public to download, use, modify, and distribute.

  8. 8

    Why does the tutorial say Python can reduce the time needed to write code?

    1. A

      Python eliminates the need to solve the problem being programmed

    2. B

      Some tasks require fewer lines of code than in other languages

    3. C

      Python automatically writes the entire application from a short description

    4. D

      Python programs never require testing or debugging

    Correct answer
    B

    Some tasks require fewer lines of code than in other languages

    Explanation

    The tutorial says Python often accomplishes tasks with fewer lines, giving a one-line Hello World program as an example.

  9. 9

    Which statement best describes object-oriented programming as discussed in the tutorial?

    1. A

      Programs must be written as one uninterrupted sequence of machine instructions

    2. B

      Programs can use only numeric values and cannot represent real-world entities

    3. C

      Programs are divided into separate operating systems for each function

    4. D

      Programs can be organized into individual objects, helping make code neat and understandable

    Correct answer
    D

    Programs can be organized into individual objects, helping make code neat and understandable

    Explanation

    The tutorial says Python supports grouping and bundling program elements into individual objects, which can make code neat and easier to understand.

  10. 10

    What is the practical meaning of Python being cross-platform?

    1. A

      A program can run on different systems only if it contains no libraries

    2. B

      A program written for Linux can run only on Linux

    3. C

      A program can execute on several operating systems only after being rewritten in each one

    4. D

      A program written on Windows can also run on Linux with little or no modification

    Correct answer
    D

    A program written on Windows can also run on Linux with little or no modification

    Explanation

    The tutorial describes cross-platform Python programs as running on systems such as Windows and Linux with little or no modification.

  11. 11

    What role do Python's libraries play, as described in the tutorial?

    1. A

      They replace the need to write any Python code

    2. B

      They prevent Python programs from running on different operating systems

    3. C

      They provide reusable functionality and flexibility, and many are cross-platform compatible

    4. D

      They restrict Python to data analysis applications

    Correct answer
    C

    They provide reusable functionality and flexibility, and many are cross-platform compatible

    Explanation

    The tutorial highlights Python's large library collection as a source of flexibility and notes that libraries can be cross-platform compatible.

  12. 12

    Which languages does the tutorial name as examples that Python can be integrated with?

    1. A

      HTML, CSS, and SQL only

    2. B

      C, C++, and Java

    3. C

      Bash, Perl, and Lua only

    4. D

      Swift, Kotlin, and Rust only

    Correct answer
    B

    C, C++, and Java

    Explanation

    The tutorial explicitly gives C, C++, and Java as examples of languages Python can be integrated with.

  13. 13

    Which is an application of Python specifically identified in the tutorial?

    1. A

      Manufacturing network hardware

    2. B

      Developing web applications of different levels of complexity

    3. C

      Designing physical computer processors

    4. D

      Replacing operating systems in all personal computers

    Correct answer
    B

    Developing web applications of different levels of complexity

    Explanation

    The tutorial identifies web application development as one of Python's applications.

  14. 14

    Why does the tutorial describe Python as a preferred choice for data analysis?

    1. A

      It does not permit the use of numerical data

    2. B

      It can analyze data only through a built-in game-development module

    3. C

      It has an abundance of relevant libraries, such as NumPy and pandas

    4. D

      It automatically collects all data without requiring a program

    Correct answer
    C

    It has an abundance of relevant libraries, such as NumPy and pandas

    Explanation

    The tutorial associates Python's use in data analysis with its abundance of libraries, including NumPy and pandas.

  15. 15

    How does the tutorial describe Python's use in machine learning?

    1. A

      It can use machine learning only when a program is also a web application

    2. B

      It is limited to displaying data and cannot support predictive analysis

    3. C

      It can implement predictive analysis using machine-learning libraries

    4. D

      It performs machine learning only by translating programs into Java

    Correct answer
    C

    It can implement predictive analysis using machine-learning libraries

    Explanation

    The tutorial says Python can implement predictive analysis using machine-learning libraries, including scikit-learn and TensorFlow.

  16. 16

    Which Python module does the tutorial associate with game development?

    1. A

      Pygame

    2. B

      Jupyter

    3. C

      NumPy

    4. D

      pandas

    Correct answer
    A

    Pygame

    Explanation

    The tutorial names Pygame as a module used for game development.

  17. 17

    Which task is an example of automation with Python in the tutorial?

    1. A

      Physically installing a computer's processor

    2. B

      Changing the source code of every operating system

    3. C

      Manually entering the same instruction each time it is needed

    4. D

      Sending emails repeatedly through a program

    Correct answer
    D

    Sending emails repeatedly through a program

    Explanation

    The tutorial gives repetitive tasks such as sending emails, opening a browser, and posting a status as automation examples.

  18. 18

    A beginner wants to learn Python for use in several possible career domains. Which characteristic most directly supports that choice?

    1. A

      Python is intended only for developing games

    2. B

      Python is restricted to one specialized domain

    3. C

      Python is used across varied domains, including web development, data science, machine learning, and automation

    4. D

      Python programs can run only on a single operating system

    Correct answer
    C

    Python is used across varied domains, including web development, data science, machine learning, and automation

    Explanation

    Python's use in many domains is presented as a consequence of its general-purpose and versatile nature.

  19. 19

    What recommendation does the tutorial make to a beginner choosing between Python 2 and Python 3?

    1. A

      Focus on Python 3 because Python 2 is becoming obsolete

    2. B

      Avoid both versions because Python cannot be used for beginner programming

    3. C

      Focus on Python 2 because development of Python 3 has stopped

    4. D

      Learn only Python 2 because Python 3 has less community support

    Correct answer
    A

    Focus on Python 3 because Python 2 is becoming obsolete

    Explanation

    The tutorial recommends Python 3 for beginners because Python 2 was becoming obsolete and more companies were moving to Python 3.

  20. 20

    What trend in company codebases does the tutorial use to illustrate the move from Python 2 to Python 3?

    1. A

      Companies were moving their Python 3 codebases back to Python 2

    2. B

      Some companies migrated substantial portions of their Python 2 codebases to Python 3

    3. C

      Companies were abandoning Python because it could not run on Linux

    4. D

      Companies were replacing all Python code with machine code

    Correct answer
    B

    Some companies migrated substantial portions of their Python 2 codebases to Python 3

    Explanation

    The tutorial cites Instagram's migration of most of its Python codebase from Python 2.7 to Python 3 as an example of the broader transition.

  21. 21

    Which reason does the tutorial give for favoring Python 3 over Python 2 for new learners?

    1. A

      It says Python 3 cannot be used with libraries

    2. B

      It says Python 2 is the only version that supports interpreted execution

    3. C

      It says Python 2 is the only version that can run on Windows

    4. D

      It describes Python 3 as receiving stronger community support and continued improvements

    Correct answer
    D

    It describes Python 3 as receiving stronger community support and continued improvements

    Explanation

    The tutorial notes stronger community support for Python 3 and says newer Python versions are receiving performance improvements, unlike Python 2.7.

  22. 22

    Which set contains only code-writing options mentioned in the tutorial?

    1. A

      A web browser, a spreadsheet, or a video player

    2. B

      A compiler, a database, or a network router

    3. C

      Python CLI, a text editor, or a Python IDE

    4. D

      An operating system, a printer, or a graphics card

    Correct answer
    C

    Python CLI, a text editor, or a Python IDE

    Explanation

    The tutorial mentions the Python CLI, text editors such as Notepad, and IDEs as options for writing code.

  23. 23

    Why does the tutorial say indentation-focused IDEs can be helpful when coding in Python?

    1. A

      They allow Python code to run without an interpreter

    2. B

      They remove all variable names from the program

    3. C

      They convert every Python program into a web page

    4. D

      They can assist with coding and debugging in a language that relies heavily on indentation

    Correct answer
    D

    They can assist with coding and debugging in a language that relies heavily on indentation

    Explanation

    The tutorial emphasizes that Python is based heavily on indentation and says IDEs can help with coding and debugging.

  24. 24

    What is Jupyter Notebook, as described in the tutorial?

    1. A

      A Python keyword used to declare integer variables

    2. B

      A game-development module included in Python

    3. C

      A compiler that turns every Python script into a machine-specific executable

    4. D

      A web-based application for writing Python code in an interactive data-science environment

    Correct answer
    D

    A web-based application for writing Python code in an interactive data-science environment

    Explanation

    The tutorial describes Jupyter Notebook as a web-based application that provides an interactive data-science environment for writing code.

  25. 25

    What is one reason the tutorial recommends installing Python through the Anaconda distribution for this setup?

    1. A

      Anaconda prevents users from installing or using libraries

    2. B

      Anaconda includes Python, Jupyter Notebook, and commonly used packages

    3. C

      Anaconda is required for Python code to run on every operating system

    4. D

      Anaconda replaces Python with a different programming language

    Correct answer
    B

    Anaconda includes Python, Jupyter Notebook, and commonly used packages

    Explanation

    The tutorial recommends Anaconda because its distribution already includes Python, Jupyter Notebook, and commonly used packages.

  26. 26

    How does the tutorial describe opening a new Python notebook from Jupyter Notebook?

    1. A

      Choose the new option and select a machine-code executable

    2. B

      Install a game module and select its source file

    3. C

      Open a text editor and select the Python CLI

    4. D

      Choose the new option and select Python 3

    Correct answer
    D

    Choose the new option and select Python 3

    Explanation

    The tutorial describes selecting New and then Python 3 to create a notebook for writing Python code.

  27. 27

    If the same value must be assigned to three variables, which form is presented as a concise option?

    1. A

      a, b, c = 10

    2. B

      a == b == c == 10

    3. C

      a = 10, b = 20, c = 30

    4. D

      a = b = c = 10

    Correct answer
    D

    a = b = c = 10

    Explanation

    Chained assignment, such as a = b = c = 10, assigns the same value to all three variables.

  28. 28

    Which assignment most directly assigns three different values to three variables in one statement?

    1. A

      x, y, z == 20, 30, 40

    2. B

      x = 20, y = 30, z = 40 as one tuple assignment

    3. C

      x = y = z = 20, 30, 40

    4. D

      x, y, z = 20, 30, 40

    Correct answer
    D

    x, y, z = 20, 30, 40

    Explanation

    The tutorial demonstrates assigning different values by matching comma-separated variables and values: x, y, z = 20, 30, 40.

  29. 29

    Which statement about declaring a variable in Python matches the tutorial?

    1. A

      A programmer must write the variable's type before every assignment

    2. B

      A programmer can assign a value without writing a type before the variable name

    3. C

      A programmer must declare every variable as a string first

    4. D

      A programmer must use a separate declaration keyword for each variable

    Correct answer
    B

    A programmer can assign a value without writing a type before the variable name

    Explanation

    The tutorial explains that Python infers the variable type from its value and shows that writing a type such as int before a variable is invalid syntax.

  30. 30

    What is a Python token, according to the tutorial?

    1. A

      A memory location used only for storing integers

    2. B

      A complete application ready to distribute

    3. C

      A command that always runs an entire program

    4. D

      A smallest meaningful component of source code

    Correct answer
    D

    A smallest meaningful component of source code

    Explanation

    A token is described as a basic, smallest meaningful component of source code.

  31. 31

    Which list gives the four token categories named in the tutorial?

    1. A

      Integers, strings, lists, and dictionaries

    2. B

      Classes, files, loops, and functions

    3. C

      Keywords, literals, identifiers, and operators

    4. D

      Comments, modules, packages, and applications

    Correct answer
    C

    Keywords, literals, identifiers, and operators

    Explanation

    The tutorial categorizes tokens as keywords, literals, identifiers, and operators.

  32. 32

    Why can a Python keyword not be used as a variable name?

    1. A

      It is always converted into a numeric literal

    2. B

      It is a reserved word with a specific purpose in the language

    3. C

      It is automatically interpreted as a file name

    4. D

      It can be used only as a string value

    Correct answer
    B

    It is a reserved word with a specific purpose in the language

    Explanation

    Keywords are reserved words with specific meanings and purposes, so they cannot be used as identifiers.

  33. 33

    What is an identifier in Python?

    1. A

      A constant value written directly in source code

    2. B

      A name given to a variable, function, or class

    3. C

      A type of executable file produced by an interpreter

    4. D

      A symbol that performs arithmetic between values

    Correct answer
    B

    A name given to a variable, function, or class

    Explanation

    The tutorial defines an identifier as a name given to a variable, function, or class.

  34. 34

    Which name follows the identifier rules described in the tutorial?

    1. A

      user@score

    2. B

      user.score

    3. C

      user_score

    4. D

      user-score

    Correct answer
    C

    user_score

    Explanation

    The tutorial says special characters are not permitted in identifiers apart from the underscore; the hyphen, period, and at sign in the other options violate that rule.

  35. 35

    Which identifier rule explains why 1280be cannot be a valid variable name?

    1. A

      An identifier cannot begin with an integer

    2. B

      An identifier must begin with a keyword

    3. C

      An identifier must contain a period

    4. D

      An identifier cannot contain any letters

    Correct answer
    A

    An identifier cannot begin with an integer

    Explanation

    The tutorial says an identifier's first character may be a letter or underscore, but not an integer.

  36. 36

    What does Python's case sensitivity mean for identifiers?

    1. A

      Only lowercase identifiers can be assigned values

    2. B

      Only uppercase identifiers can refer to variables

    3. C

      A and a are treated as different identifiers

    4. D

      A and a are always treated as the same identifier

    Correct answer
    C

    A and a are treated as different identifiers

    Explanation

    The tutorial demonstrates that uppercase A and lowercase a are distinct identifiers in Python.

  37. 37

    Which statement about Python string literals is correct?

    1. A

      A string must always be enclosed in parentheses

    2. B

      A string must be declared with a string type before its quotes

    3. C

      A string can be enclosed only in double quotes

    4. D

      A string can be enclosed in either single quotes or double quotes

    Correct answer
    D

    A string can be enclosed in either single quotes or double quotes

    Explanation

    The tutorial says both single and double quotes can delimit string literals.

  38. 38

    How does the tutorial show a multiline string being represented?

    1. A

      By placing a separate type declaration before every line

    2. B

      By enclosing the text in three matching quote characters

    3. C

      By using square brackets around each line

    4. D

      By placing a comma after every line of text

    Correct answer
    B

    By enclosing the text in three matching quote characters

    Explanation

    The tutorial demonstrates enclosing multiline text in triple quotes.

  39. 39

    Which description of a numeric literal matches the tutorial?

    1. A

      It can represent a positive or negative number and may include a decimal point

    2. B

      It can contain letters only and cannot represent a number

    3. C

      It must be a positive whole number with no sign

    4. D

      It must contain exactly two decimal points

    Correct answer
    A

    It can represent a positive or negative number and may include a decimal point

    Explanation

    The tutorial describes numeric literals as using digits, potentially with a positive or negative sign and a decimal point.

  40. 40

    According to the tutorial, what does a decimal point indicate in a numeric literal?

    1. A

      The value is necessarily a Boolean

    2. B

      The value is a string literal

    3. C

      The value is a floating-point number

    4. D

      The value is an identifier

    Correct answer
    C

    The value is a floating-point number

    Explanation

    The tutorial distinguishes integers without a decimal point from floating-point values that include one.

  41. 41

    Which pair gives the two Boolean literal values named in the tutorial?

    1. A

      Null and None

    2. B

      1 and 2

    3. C

      True and False

    4. D

      Yes and No

    Correct answer
    C

    True and False

    Explanation

    The tutorial identifies True and False as the two Boolean literals and notes that they are also keywords.

  42. 42

    What does the special literal None represent in the tutorial?

    1. A

      A string containing the word null

    2. B

      A numeric value equal to zero

    3. C

      A Boolean value that is always true

    4. D

      A field or value that is not created or is absent

    Correct answer
    D

    A field or value that is not created or is absent

    Explanation

    The tutorial describes None as a special literal used to specify a field that is not created and compares it with null in some other languages.

  43. 43

    Which set contains only the four immutable data types listed in the tutorial?

    1. A

      Numbers, lists, and dictionaries

    2. B

      Lists, dictionaries, and sets

    3. C

      Numbers, strings, and tuples

    4. D

      Strings, sets, and lists

    Correct answer
    C

    Numbers, strings, and tuples

    Explanation

    The tutorial lists numbers, strings, and tuples as immutable data types.

  44. 44

    Which set contains only the mutable data types listed in the tutorial?

    1. A

      Lists, dictionaries, and sets

    2. B

      Tuples, dictionaries, and numbers

    3. C

      Numbers, lists, and strings

    4. D

      Numbers, strings, and tuples

    Correct answer
    A

    Lists, dictionaries, and sets

    Explanation

    The tutorial lists lists, dictionaries, and sets as mutable data types.

  45. 45

    What is the difference between mutable and immutable data types in the tutorial?

    1. A

      Mutable data is inferred, while immutable data must be declared

    2. B

      Mutable data is always local, while immutable data is always global

    3. C

      Mutable data can contain numbers, while immutable data can contain only text

    4. D

      Mutable data can be changed, while immutable data cannot be changed

    Correct answer
    D

    Mutable data can be changed, while immutable data cannot be changed

    Explanation

    The tutorial defines mutable data as changeable and immutable data as not changeable or modifiable.

  46. 46

    Which group contains the numeric types named in the tutorial's discussion of numbers?

    1. A

      Integer, keyword, identifier, and operator

    2. B

      Boolean, character, array, and class

    3. C

      String, tuple, list, and dictionary

    4. D

      Integer, long integer, floating-point, and complex number

    Correct answer
    D

    Integer, long integer, floating-point, and complex number

    Explanation

    The tutorial names integer, long integer, floating-point, and complex number as numeric types.

  47. 47

    Which built-in function does the tutorial use to inspect a variable's data type?

    1. A

      find()

    2. B

      replace()

    3. C

      printtype()

    4. D

      type()

    Correct answer
    D

    type()

    Explanation

    The tutorial uses the type() function to check whether values are integers, strings, or floats.

  48. 48

    What does indexing a string with position 0 retrieve?

    1. A

      Its first character

    2. B

      The entire string with its first character removed

    3. C

      Its last character

    4. D

      The number of characters in the string

    Correct answer
    A

    Its first character

    Explanation

    The tutorial uses index 0 to retrieve the first character of a string.

  49. 49

    In the tutorial's string-indexing example, what does index -1 retrieve?

    1. A

      The character before the first character

    2. B

      The last character of the string

    3. C

      The first character of the string

    4. D

      The string's length

    Correct answer
    B

    The last character of the string

    Explanation

    The tutorial uses index -1 to access the last character of a string.

  50. 50

    When extracting a substring from index 0 up to index 5, which characters are included according to the tutorial?

    1. A

      Characters at positions 0 through 4

    2. B

      Only the character at position 5

    3. C

      Characters at positions 1 through 5

    4. D

      Characters at positions 0 through 5

    Correct answer
    A

    Characters at positions 0 through 4

    Explanation

    The tutorial explains that the ending index is excluded, so a slice from 0 to 5 includes positions 0 through 4.

  51. 51

    What does the string find() method return in the example described?

    1. A

      The number of times the substring appears

    2. B

      A Boolean indicating whether the string is empty

    3. C

      The position where the requested substring begins

    4. D

      A new string with the requested substring removed

    Correct answer
    C

    The position where the requested substring begins

    Explanation

    The tutorial says find() returns the position of the requested substring; it gives the starting position of the match.

  52. 52

    What is the purpose of the string replace() method?

    1. A

      To convert a string into an integer automatically

    2. B

      To return the starting position of a substring

    3. C

      To retrieve a string's final character

    4. D

      To replace one character or substring with another

    Correct answer
    D

    To replace one character or substring with another

    Explanation

    The tutorial presents replace() as a way to substitute one character or string with another.

  53. 53

    In the tutorial's example of replacing a word ending with "ment" with a space, what is the result of the operation?

    1. A

      The matching portion is moved to the beginning of the text

    2. B

      The matching "ment" portion is removed from the resulting text

    3. C

      The entire string is converted to uppercase

    4. D

      The method returns only the position of "ment"

    Correct answer
    B

    The matching "ment" portion is removed from the resulting text

    Explanation

    Replacing the substring "ment" with a space removes that portion from the resulting text, as illustrated by changing "attachment" to "attach".

  54. 54

    Which statement about Python's conversion between numeric types is made in the tutorial?

    1. A

      Python converts every numeric value to a complex number

    2. B

      Python never converts numeric values between types

    3. C

      Python can automatically convert a number from one type to another when appropriate

    4. D

      Python requires a string conversion before any numeric conversion

    Correct answer
    C

    Python can automatically convert a number from one type to another when appropriate

    Explanation

    The tutorial says Python automatically converts a number from one type to another when appropriate, and also mentions explicit conversion functions.

  55. 55

    Which group contains functions the tutorial names for explicitly converting numeric values?

    1. A

      int(), long(), float(), and complex()

    2. B

      type(), find(), replace(), and print()

    3. C

      list(), tuple(), dict(), and set()

    4. D

      and(), or(), not(), and in()

    Correct answer
    A

    int(), long(), float(), and complex()

    Explanation

    The tutorial names int, long, float, and complex functions as explicit numeric conversion options.

  56. 56

    Which operator category is used to perform calculations such as addition, subtraction, multiplication, and division?

    1. A

      Identity operators

    2. B

      Membership operators

    3. C

      Arithmetic operators

    4. D

      Assignment operators

    Correct answer
    C

    Arithmetic operators

    Explanation

    Arithmetic operators perform calculations such as addition, subtraction, multiplication, division, and modulo.

  57. 57

    What is the role of the assignment operator in an expression such as var = 10?

    1. A

      It tests whether var is greater than 10

    2. B

      It checks whether 10 belongs to a sequence

    3. C

      It assigns the value 10 to the variable var

    4. D

      It converts var into a string

    Correct answer
    C

    It assigns the value 10 to the variable var

    Explanation

    The tutorial identifies the equals sign in var = 10 as an assignment operator that assigns a value to a variable.

  58. 58

    If var is 10, what does var += 10 do?

    1. A

      It adds 10 to var and assigns the result back to var

    2. B

      It subtracts var from 10 and stores the result elsewhere

    3. C

      It assigns 10 to var only if var is already zero

    4. D

      It compares var with 10 and returns a Boolean

    Correct answer
    A

    It adds 10 to var and assigns the result back to var

    Explanation

    The shorthand assignment var += 10 means var = var + 10, so var becomes 20 when it initially equals 10.

  59. 59

    What kind of result does a comparison operator produce?

    1. A

      A list containing the two operands

    2. B

      A string containing the compared values

    3. C

      A Boolean value, True or False

    4. D

      A new variable type

    Correct answer
    C

    A Boolean value, True or False

    Explanation

    Comparison operators compare values and return True or False.

  60. 60

    Which statement best describes the logical operator and?

    1. A

      It checks whether one value is inside a sequence

    2. B

      It produces True whenever either condition is True

    3. C

      It reverses the truth value of one condition

    4. D

      It produces True only when both conditions are True

    Correct answer
    D

    It produces True only when both conditions are True

    Explanation

    The tutorial explains logical and using Boolean values: both operands must be true for the result to be true.

  61. 61

    What does the logical operator not do to a Boolean condition?

    1. A

      It reverses the condition's truth value

    2. B

      It adds the values of two conditions

    3. C

      It shifts the bits of an integer

    4. D

      It checks whether two objects have the same identity

    Correct answer
    A

    It reverses the condition's truth value

    Explanation

    The logical operator not negates a condition, changing True to False or False to True.

  62. 62

    Which operation is performed by bitwise operators?

    1. A

      Operations that assign values to multiple variables

    2. B

      Operations that compare text alphabetically

    3. C

      Operations only on variable names

    4. D

      Operations on the binary bits of values

    Correct answer
    D

    Operations on the binary bits of values

    Explanation

    Bitwise operators work on the binary representation of values.

  63. 63

    What is the result of the bitwise OR operation 7 | 5?

    1. A

      12

    2. B

      5

    3. C

      7

    4. D

      2

    Correct answer
    C

    7

    Explanation

    Seven is 111 in binary and five is 101. OR gives 111, which is 7.

  64. 64

    What is the result of the bitwise AND operation 7 & 5?

    1. A

      7

    2. B

      12

    3. C

      5

    4. D

      2

    Correct answer
    C

    5

    Explanation

    Seven is 111 in binary and five is 101. AND gives 101, which is 5.

  65. 65

    According to the tutorial's example, what is the result of applying bitwise NOT to 7?

    1. A

      8

    2. B

      -8

    3. C

      -7

    4. D

      7

    Correct answer
    B

    -8

    Explanation

    The tutorial gives the result of NOT 7 as -8, explaining it through the inverted binary representation.

  66. 66

    What does a right shift by two positions do to the binary representation of a value?

    1. A

      Moves its bits two positions to the left

    2. B

      Changes every bit from 0 to 1 and from 1 to 0

    3. C

      Reverses the order of all bits without shifting

    4. D

      Moves its bits two positions to the right

    Correct answer
    D

    Moves its bits two positions to the right

    Explanation

    A right-shift operation moves bits toward the right by the specified number of positions; the tutorial gives 10 >> 2 = 2 as an example.

  67. 67

    What is the result of the tutorial's example 10 << 2?

    1. A

      5

    2. B

      40

    3. C

      2

    4. D

      20

    Correct answer
    B

    40

    Explanation

    The tutorial shows that shifting 10 left by two positions gives 40; in binary, 1010 becomes 101000.

  68. 68

    What do the identity operators is and is not test, as described in the tutorial?

    1. A

      Whether two values are numerically ordered

    2. B

      Whether two operands share an identity

    3. C

      Whether an expression contains a decimal point

    4. D

      Whether a value occurs in a sequence

    Correct answer
    B

    Whether two operands share an identity

    Explanation

    The tutorial describes is and is not as operators for testing whether two operands share an identity.

  69. 69

    What do the membership operators in and not in test?

    1. A

      Whether a number can be divided evenly

    2. B

      Whether a variable has been assigned a data type

    3. C

      Whether a value is present in a sequence such as a list, string, or tuple

    4. D

      Whether two variables have the same identity

    Correct answer
    C

    Whether a value is present in a sequence such as a list, string, or tuple

    Explanation

    Membership operators test whether a value is a member of a sequence, such as a list, string, or tuple.

  70. 70

    A program checks whether "wolf" occurs in a collection containing "dog", "cat", and "wolf". What should the membership test return?

    1. A

      True only if wolf is the first element

    2. B

      False, because a collection can contain only one element

    3. C

      False, because membership tests work only on strings

    4. D

      True, because wolf is an element of the collection

    Correct answer
    D

    True, because wolf is an element of the collection

    Explanation

    The tutorial's membership example returns True when the searched-for value, wolf, is present in the list.

Question 1 of 70
Question 1 of 70

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent