Free Online Flashcard Deck

2 Variables and Data Types Free Online FlashCards

Study 2 Variables and Data Types with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What does dynamically typed mean in Python?

Back

Python is dynamically typed: a name has no permanently declared type and may later refer to a value of a different type.

02
Front

What rules apply to Python names?

Back

A Python name may contain letters, digits, and underscores, but it cannot begin with a digit. Names are case-sensitive, and keywords cannot be ordinary names.

03
Front

How do `=` and `==` differ?

Back

The operator `=` assigns or binds a value to a name; it does not test mathematical equality. The comparison operator `==` tests whether two values are equal.

04
Front

What happens when a name is rebound?

Back

Assignment can rebind a name. After `temperature = 18` followed by `temperature = 21`, the name `temperature` refers to `21`.

05
Front

Why can `x, y = y, x` swap values?

Back

In `x, y = y, x`, Python evaluates the right-hand side before assignments take effect, so the two values are swapped without a temporary variable.

06
Front

How can you inspect an object's type?

Back

The `type()` function inspects an object and reports its type, such as `int`, `float`, `str`, or `bool`.

07
Front

What do `/`, `//`, `%`, and `**` do?

Back

`/` performs ordinary division, `//` performs floor division, `%` returns the remainder, and `**` raises a value to a power.

08
Front

What type does `input()` return?

Back

`input()` returns a string. Convert it before numeric operations, such as with `age = int(input("Enter your age: "))`.

09
Front

How does `int()` convert a float?

Back

Converting a float to `int` discards the fractional part rather than rounding: `int(7.9)` is `7` and `int(-7.9)` is `-7`.

10
Front

What does string immutability mean?

Back

Strings are immutable Unicode sequences, so their contents cannot be changed in place. Create a new string instead, such as by concatenating text.

11
Front

How does Python index strings?

Back

Python strings use zero-based indexing: `word[0]` returns the first character. Negative indexing counts from the end, so `word[-1]` returns the last character.

12
Front

What is an f-string used for?

Back

An f-string inserts expressions directly into text, as in `f"You ordered {quantity} {item}s."`. It provides readable formatted output.