Formatting, operators, escape sequences

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

Subset (Set Operation)

Test whether every element in set s is in set t using the syntax: s \le t

2
New cards

Superset (Set Operation)

Test whether every element in set t is in set s using the syntax: s \ge t

3
New cards

Union (Set Operation)

Create a new set with elements from both set s and set t using the syntax: s | t

4
New cards

Intersection (Set Operation)

Create a new set with elements common to both set s and set t using the syntax: s & t

5
New cards

Difference (Set Operation)

Create a new set with elements in set s but not in set t using the syntax: s - t

6
New cards

Symmetric Difference (Set Operation)

Create a new set with elements in either set s or set t but not both, using the syntax: s \text{^} t

7
New cards

f-string format specifier: Left-align string in a field of 20 characters

Syntax: {name:<20}

8
New cards

f-string format specifier: Center-align string in a field of 20 characters

Syntax: {name:^20}

9
New cards

f-string format specifier: Right-align string in a field of 20 characters

Syntax: {name:>20}

10
New cards

f-string format specifier: Right-align string with zero-padding in a field of 20 characters

Syntax: {name:0>20}

11
New cards

f-string example for zero-padding numbers

for i in range(5, 16):
    print(f'{i:03}')
# Example output for i = 5: '005'

12
New cards

f-string example for floating-point precision

pi = 3.14159265
f'Pi is equal to {pi:.4f}'
# Output: 'Pi is equal to 3.1416'

13
New cards

Cloning Lists (Slicing)

Creating a new list that is a shallow copy of an existing list by using full slicing.

Example:

a = [5, 3, 6, 1]
b = a[:]
a[1] = 42
# 'a' is now [5, 42, 6, 1], but 'b' remains [5, 3, 6, 1]

14
New cards

List Comprehension

A concise way to create lists.

Syntax: [\text{expression for item in iterable if conditional}]

Example: [x*2 for x in range(5) if x % 2 == 0] (results in [0, 4, 8])

15
New cards

Escape Sequence: \n

Ends the current line of text and starts a new one (newline character).

16
New cards

Escape Sequence: \t

Skips to the next "tab stop" in the text (tab character).

17
New cards

Escape Sequence: \'

Used to include a single quote within a string delimited by single quotes without ending the string.

18
New cards

Escape Sequence: \"

Used to include a double quote within a string delimited by double quotes without ending the string.

19
New cards

Escape Sequence: \

Used to include a literal backslash character in a string.