Flashcards: Python Data Handling and String Formatting — 20 cards

All cards

1Question

Dictionary comparison — method?

Answer

Use `==` for equality; `cmp()` in Python 2.

2Question

keys() — returns?

Answer

A view object of all dictionary keys.

3Question

dict() — creates?

Answer

A dictionary from sequences of key-value pairs.

4Question

KeyError — when?

Answer

Accessing a non-existent dictionary key.

5Question

String format() — purpose?

Answer

Insert variables into strings dynamically.

6Question

!r and !s — in format?

Answer

Control object representation: repr() vs str().

7Question

String repetition — operator?

Answer

The `*` operator repeats strings.

8Question

String slicing — syntax?

Answer

[start:stop:step] to extract substrings.

9Question

count() — does?

Answer

Counts occurrences of a substring in a string.

10Question

replace() — does?

Answer

Replaces substrings within a string.

11Question

open() — mode?

Answer

Specifies file access: 'r', 'w', etc.

12Question

read(n) — reads?

Answer

n characters from an open file.

13Question

readline() — reads?

Answer

A single line from a file.

14Question

try-except-else — purpose?

Answer

Handle exceptions during file operations.

15Question

Python file modes?

Answer

'r' for read, 'w' for write, 'b' for binary.

16Question

Python data types?

Answer

Int, float, string, list, tuple, dict.

17Question

Mutable data structure?

Answer

List and dict are mutable; tuple is immutable.

18Question

Set — characteristics?

Answer

Unordered, unique elements, supports set operations.

19Question

Variables — rules?

Answer

Start with letter/underscore, case-sensitive.

20Question

Functions — define with?

Answer

Using `def` keyword, reusable code blocks.

Test yourself with the quiz

Test your knowledge with 10 questions on Python Data Handling and String Formatting.

1. How do you create a Python dictionary from a list of key-value pair tuples?

2. What is the purpose of the 'cmp()' function in Python 2 when used with dictionaries?

Take the quiz →

Read the revision sheet

Review the complete course in the revision sheet for Python Data Handling and String Formatting.

See revision sheet →

Similar courses

Create your own flashcards

Import your course and AI generates flashcards in 30 seconds.

Flashcard generator