Lecture Notes on Strings, Conditions, and Control Structures

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

1/85

flashcard set

Earn XP

Description and Tags

A comprehensive set of vocabulary flashcards based on lecture notes covering string manipulation, condition evaluation, and control structures in programming.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

86 Terms

1
New cards

String.expandtabs(integer)

Method to set the size of tab increments in a string.

2
New cards

Default increment for \t

8 spaces.

3
New cards

string.format(data)

Formats data of various types into a string.

4
New cards

Data types used with string.format()

Includes list, string, integer, float.

5
New cards

General format for string formatting

{index:how to format}.

6
New cards

Right justification in format specifier

Uses > symbol.

7
New cards

Center justification in format specifier

Uses ^ symbol.

8
New cards

Left justification in format specifier

Uses < symbol.

9
New cards

Example format string

"I have {0:>5d} {1:^7s}! ${2:<6.2f}".

10
New cards

Boolean conditions

Always result in True or False.

11
New cards

Relational operators

Operators that compare values: >,

12
New cards

Cannot compare

Numbers and strings.

13
New cards

String operators

Operators to check if a string exists in another string.

14
New cards

Character comparison

Compares strings character by character.

15
New cards

ASCII value of 'A'

65.

16
New cards

ASCII value of 'a'

97.

17
New cards

ord() function

Converts a character to its ASCII value.

18
New cards

chr() function

Converts an ASCII value to its character.

19
New cards

Logic behind logical operators

Create complex conditions resulting in True or False.

20
New cards

Operator precedence (high to low)

Math operators > Relational operators > Logical operators.

21
New cards

Logical AND operator

Only true if all conditions are true.

22
New cards

Logical OR operator

True if at least one condition is true.

23
New cards

Logical NOT operator

Inverts the truth value of a condition.

24
New cards

Boolean data type

Consists only of True and False.

25
New cards

isinstance() function

Checks the data type of a value.

26
New cards

stringA.startswith(stringB)

Checks if stringA starts with stringB.

27
New cards

stringA.endswith(stringB)

Checks if stringA ends with stringB.

28
New cards

string.isupper()

True if all letters are uppercase.

29
New cards

string.islower()

True if all letters are lowercase.

30
New cards

string.isdigit()

True if all characters are digits (0-9).

31
New cards

string.isalpha()

True if all characters are letters (upper or lower).

32
New cards

string.alnum()

True if all characters are letters or digits.

33
New cards

string.isspace()

True if all characters are whitespace.

34
New cards

if/else statement

Provides two options based on a condition.

35
New cards

Decision structure

Using conditions to control flow in a program.

36
New cards

Input example

Input commands to determine user menus (Lunch/Dinner).

37
New cards

Nested if/else statement

Any number of options can be evaluated.

38
New cards

while loops

Condition-controlled loops that execute as long as the condition is true.

39
New cards

Loop variable

Variable tested by the loop's condition.

40
New cards

Iteration

One execution of the loop body.

41
New cards

While loop general format

while condition(s): # code to repeat.

42
New cards

Example: Display blue 5 times.

Using a while loop with a count variable.

43
New cards

User-controlled loops

Loops that continue based on user input.

44
New cards

Input validation

Checking if user input is valid.

45
New cards

Sentinels in loops

Unique values indicating the loop should stop.

46
New cards

Break statement

Causes immediate exit from the loop.

47
New cards

Continue statement

Skips the current iteration of the loop.

48
New cards

sum of 1-5 using loop

Accumulates total using a while loop.

49
New cards

Display multiples of 3

Using a loop to print multiples between 1 and 50.

50
New cards

List data for formatting

Includes types: int, str, float, bool.

51
New cards

Input validation example

Asks for number 1-10, repeats if invalid.

52
New cards

Check for valid color input

Loops until 'RED' or 'BLUE' is entered.

53
New cards

False condition checks

Using logical operators in decision making.

54
New cards

Weight condition example

Checks if a pet is a dog and under 30 lbs.

55
New cards

Menu selection example

Determines food options based on user input.

56
New cards

General format for checking data type

isinstance(value, data type).

57
New cards

String starts and ends checks

Using string functions to verify position.

58
New cards

Returning boolean results

Evaluates conditions to return True/False.

59
New cards

Using formats for output

Standard format syntax for displaying data.

60
New cards

Character conversion to ASCII

Using ord() to get the numerical value.

61
New cards

Display formatted strings with variables

Incorporating data into strings via formatting.

62
New cards

Comparison of strings

Determined through ASCII values.

63
New cards

Character comparison using relational operators

To evaluate strings logically.

64
New cards

True and False in logical conditions

Utilizing Boolean logic.

65
New cards

Iterate through loop until condition fails

Using while for condition control.

66
New cards

Truth table for logical operators

Visualizing outcomes of AND, OR, NOT.

67
New cards

Data validation loops

Enforcing correct user input.

68
New cards

Accessing list elements via index

Using indices to retrieve formatted strings.

69
New cards

Predicting outcomes based on inputs

Using if-else structures to guide program flow.

70
New cards

Incrementing loop counters

Updating variables within loops gracefully.

71
New cards

Loop exit strategies

Implementing break and continue for control.

72
New cards

Using formatted strings for clarity

Enhancing readability through structured output.

73
New cards

Evaluating conditions with logical operators

Determining if conditions yield a boolean result.

74
New cards

Retrieving user's favorite colors

Through looping until a condition is met.

75
New cards

Ending a loop with a sentinel

Using specific values to stop iteration.

76
New cards

Displaying output effectively

Using print statements strategically.

77
New cards

Validating conditions with relational operators

Comparing values for decision making.

78
New cards

Creating complex conditions with logical operators

Combining multiple truth checks.

79
New cards

Memorizing ASCII table values

Knowing key character encodings.

80
New cards

String formatting with indices

Positioning data for clear output.

81
New cards

Representing data types in programming

Understanding int, str, float, and bool.

82
New cards

Defining conditions for execution paths

Structuring execution based on true/false outcomes.

83
New cards

Enforcing character case checks

Using isupper() and islower() methods.

84
New cards

Displaying conditional outputs

Using print structures within decision frameworks.

85
New cards

Retaining string integrity while manipulating

Ensuring strings maintain their value after checks.

86
New cards

Evaluating menu options via user input

Navigating choices based on what user selects.