To represent binary data in Python, you would use the ____ data type.

  • binary
  • binary_data
  • bit
  • bytes

In Python, the bytes data type is used to represent binary data. It is a sequence of bytes, which is often used for working with binary files, network protocols, and other low-level data operations.

The ____ built-in function is used to convert a variable to an integer data type, if possible.

  • convert()
  • int()
  • parse()
  • str2int()

The int() built-in function in Python is used to convert a variable to an integer data type. If the variable can be converted to an integer, it will do so; otherwise, it will raise a ValueError if the conversion is not possible.

In Python, the ____ method is used to get the length of a string.

  • count()
  • len()
  • size()
  • str_len()

In Python, the len() method is used to get the length (number of characters) of a string. It is a built-in function that works with strings, lists, tuples, and other iterable objects.

The ____ keyword is used to create a new variable and assign it a specific data type.

  • define
  • int
  • type
  • var

In Python, the type keyword is used to create a new variable and assign it a specific data type. For example, x = type(5) would assign the integer type to the variable x.

To concatenate two strings in Python, you can use the ____ operator.

  • -
  • *
  • /
  • +

In Python, you can concatenate two strings using the + operator. For example, "Hello, " + "world" would result in "Hello, world".

In Python, a ____ is a built-in data type used to store multiple items in a single variable.

  • dictionary
  • list
  • string
  • tuple

In Python, a list is a built-in data type that is used to store multiple items in a single variable. Lists are ordered and mutable, making them suitable for a wide range of applications.

How can you create a new instance of a custom class and assign it to a variable in Python?

  • class.new()
  • MyClass()
  • MyClass.new()
  • new MyClass()

In Python, you create a new instance of a custom class using the class name followed by parentheses. This creates a new object of the class and can be assigned to a variable.

What is the difference between is and == when comparing variables in Python?

  • is compares object identity, checking if two variables refer to the same object. == compares object values, checking if two variables have the same content.
  • is compares object values, checking if two variables have the same content. == compares object identity, checking if two variables refer to the same object.
  • is is used for deep equality comparisons, while == is used for shallow equality comparisons.
  • is is used for strict equality comparisons, while == is used for loose equality comparisons.

This means that is checks if both variables point to the same memory location, while == checks if the values of the objects are equal.

How would you define a variable that can store a lambda function calculating the square of a number in Python?

  • def square_lambda(x): return x * x
  • let square_lambda = (x) => x * x;
  • square_lambda = lambda x: x * x
  • var square_lambda = function(x) { return x * x; }

In Python, you can define a variable to store a lambda function using the lambda keyword, as shown in option 1. This creates a function that takes an argument x and returns its square.

Which Python built-in function would you use to find the type of a variable?

  • datatype()
  • gettype()
  • type()
  • typeof()

In Python, the type() function is used to find the type of a variable. For example, type(x) will return the type of the variable x. The other options are not valid Python functions for this purpose.