1/22
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Escape Sequences
An escape sequence is a combination of characters preceded by a backslash (`\`) used to represent special characters within strings.
\n
It represents a newline character, which moves the cursor to the beginning of the next line.
\t
By using the escape sequence \t, which inserts a tab.
\'
By using the escape sequence __ to represent a single quote within a string.
\\
By using the escape sequence __ to represent a backslash character within a string.
Comprehensions
____ are concise ways to create sequences such as lists, dictionaries, and sets.
List Comprehension
By using square brackets (`[]`) enclosing an expression followed by a for clause, like [x**2 for x in range(10)].
Dictionary Comprehension
A ___ comprehension returns a dictionary created from an expression and a for loop within curly braces (`{}`).
Set Comprehension
By using curly braces (`{}`) enclosing an expression followed by a for clause, like {x**2 for x in range(10)}.
Dictionaries
A _______is an unordered collection of items, where each item is a key-value pair.
Accessing Values
By specifying the key within square brackets (`[]`), like my_dict['key1'].
Adding Key-Value Pair
By assigning a value to a new key, like my_dict['key3'] = 'value3'.
Removing Key-Value Pair
By using the del keyword followed by the dictionary name and the key to be deleted, like del my_dict['key2']. Alternatively using the .pop() method
Sets
A ___ is an unordered collection of unique elements.
Adding Element
By using the add() method, like my_set.add(4).
Removing Element
By using the remove() method, like my_set.remove(3).
Union of Sets
The | operator, like set1 | set2.
Objects/Classes
A class is a blueprint for creating objects in Python.
Defining a Class
By using the class keyword followed by the class name and a colon, like class MyClass:.
__init__ Method
It is a special method called the constructor, used to initialize objects of the class.
Creating an Object
By calling the class name followed by parentheses and any required arguments, like obj1 = MyClass(5).
Inheritance
___ is the mechanism of basing a new class on an existing class, inheriting its attributes and methods.
Encapsulation
By using private variables, indicated by prefixing variable names with double underscores __.