1/16
Flashcards covering variables, common data types (int, float, str, bool), dynamic typing, and the print(), type(), and isinstance() built-in functions in Python.
What does it mean that Python is a dynamically typed programming language?
It means you do not have to manually specify a variable's data type when creating it; Python automatically determines the data type based on the assigned value.
Can a variable in Python change its data type after its initial assignment?
Yes. A variable can later be assigned a value of a different data type (for example, reassigning a variable holding the integer 25 to the string 'Twenty-five').
What is the key difference between the integer and float data types in Python?
Integers are whole numbers without decimals (such as 10 or -5), whereas floats are numbers with decimal points (such as 4.41, 4.50, or -0.4).
How is a string defined in Python?
A string is a sequence of characters enclosed in either single (') or double (") quotation marks.
What values can the Boolean data type have in Python?
A Boolean value is written as either True or False.
What is the terminal in Python programming?
The terminal is the area where you can see text output from a program.
What is the purpose of Python's built-in print() function?
The print() function sends text and other values to the terminal.
What is the output when print('Hello', 'world!') is executed?
Hello world!
Why does print('My favorite colors are', 'blue', 'green', 'red') output all items separated by spaces on a single line?
Because separating values with commas when passing arguments into the print() function automatically adds spaces between them.
What will be the output of print(type(developer)) if developer = 'Devin'?
What error message is produced if no arguments are passed to the type() function?
TypeError: type() takes 1 or 3 arguments
What does print(type(my_boolean_var)) output if my_boolean_var = True?
What error occurs when attempting mathematical division on a string and an integer, such as '12' / 2?
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Which built-in Python function is used to verify whether a variable matches a specific data type?
isinstance()
What does isinstance(account_balance, int) return if account_balance = '12'?
False, because account_balance is assigned a string value.
How can you check if a variable belongs to one of multiple data types using isinstance()?
By passing a tuple of types as the second argument, such as isinstance(account_balance, (int, float)).
What does isinstance(account_balance, (int, float)) return when account_balance = 12?
True, because account_balance is an integer, which is one of the specified types in the tuple.