Python Lecture Notes Review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/46

flashcard set

Earn XP

Description and Tags

Flashcards for reviewing Python programming concepts covered in the lecture.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

47 Terms

1
New cards

What are variables used for in Python?

To temporarily store data in computer’s memory.

2
New cards

What are the four basic data types in Python as discussed in the notes?

Integer (int), Float, String, Boolean

3
New cards

What is the purpose of comments in Python code?

To add notes to the code, explaining the hows and whys, add reminders, explain assumptions, and reasons for specific code implementations.

4
New cards

How do you receive input from the user in Python?

By calling the input() function.

5
New cards

What data type does the input() function return?

String

6
New cards

How can you define strings in Python?

Using single (' ') or double (" ") quotes.

7
New cards

How do you define a multi-line string?

Surround the string with triple quotes (""").

8
New cards

How do you access individual characters in a string?

Using square brackets [] with the index of the character.

9
New cards

What does string slicing achieve?

Returns a substring of the original string, based on specified start and end indices.

10
New cards

What are formatted strings?

Formatted strings allow you to dynamically insert values into strings.

11
New cards

How do you convert a string to uppercase in Python?

Using the upper() method.

12
New cards

How do you find the index of the first occurrence of a character in a string?

Using the find() method.

13
New cards

How do you replace characters in a string?

Using the replace() method.

14
New cards

How do you check if a string contains a character or sequence of characters?

Using the 'in' operator.

15
New cards

List the common arithmetic operators in Python.

  • (addition), - (subtraction), * (multiplication), / (division), // (floor division), % (modulus), ** (exponentiation)
16
New cards

Which operator returns the remainder of a division?

% (Modulus operator)

17
New cards

What does the augmented assignment operator do?

It combines an arithmetic operation with an assignment (e.g., x += 10 is equivalent to x = x + 10).

18
New cards

What is operator precedence?

The order in which operations are performed in an expression. (Parenthesis, Exponentiation, Multiplication/Division, Addition/Subtraction)

19
New cards

What is the syntax for an if statement in Python?

if condition: … elif condition: … else: …

20
New cards

What are logical operators?

and, or, not

21
New cards

What are comparison operators?

(greater than), >= (greater than or equal to), < (less than), <= (less than or equal to), == (equals), != (not equals)

22
New cards

What is the syntax for a while loop in Python?

while condition: …

23
New cards

What is the syntax for a for loop in Python?

for i in range(start, end, step): …

24
New cards

What does range(5) generate?

0, 1, 2, 3, 4

25
New cards

What is a list in Python?

An ordered, mutable sequence of items.

26
New cards

How do you access the first item in a list?

numbers[0]

27
New cards

How do you add an item to the end of a list?

numbers.append(item)

28
New cards

How do you insert an item at a specific index in a list?

numbers.insert(index, item)

29
New cards

What are tuples?

Read-only lists. Once defined cannot add/remove/change items.

30
New cards

How do you unpack a tuple into separate variables?

x, y, z = coordinates

31
New cards

What are dictionaries used for?

To store key/value pairs.

32
New cards

How do you access a value in a dictionary?

customer["name"] or customer.get("name", defaultValue)

33
New cards

What are functions used for?

To break up code into small, reusable chunks that are easier to read, understand, and maintain.

34
New cards

What is the difference between parameters and arguments?

Parameters are placeholders in the function definition, while arguments are the actual values passed to the function when it's called.

35
New cards

What are the two types of arguments?

Positional arguments and Keyword arguments

36
New cards

What is returned if a function doesn't have a return statement?

None

37
New cards

What are exceptions?

Errors that crash programs.

38
New cards

How do you handle exceptions in Python?

Using try…except blocks.

39
New cards

What are classes used for?

To define new types.

40
New cards

What is a method?

A function that is part of a class.

41
New cards

What is an object?

An instance of a class.

42
New cards

What is the purpose of the init method?

It's a constructor that gets called when creating new objects to initialize them.

43
New cards

What is inheritance?

A technique to remove code duplication by creating a base class with common methods and having other classes inherit those methods.

44
New cards

What is a module?

A file with some Python code. Used to break up programs into multiple files.

45
New cards

How can you import modules?

import modulename or from modulename import object

46
New cards

What is a package?

A directory with init.py in it which contains one or more modules.

47
New cards

What is the Python Standard Library?

A huge library of modules for performing common tasks such as sending emails, working with date/time, generating random values, etc.