Python Flashcards

Week 1.2, 1.3, 1.4, 1.5, 1.6 (36 cards)

1
Q

variable

A

a named location in memory that stores a value which can be changed during execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

naming rules of variables

A
  1. no spaces, symbols
  2. start with a letter
  3. don’t use reserved rules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

name some string functions

A
  • capatalise()
  • count()
  • find()
  • index()
  • isalnum()
  • isalpha()
  • lower()
  • upper()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

syntax for f-strings

A

print(f”Name:{name}, Age:{name}, Heigt:{name}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

truthy values

A
  • non-0 numbers
  • non-empty strings
  • non-empty data structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

falsey values

A
  • 0
  • none (python equivalent to Null)
  • empty string
  • empty data structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

match-case statement

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

list syntax

A

[]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

list functions

A
  • append(item)
  • insert(index, item)
  • pop(index)
  • remove(item)
  • index(item)
  • clear()
  • reverse()
  • sort()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

tuple definition

A

ordered, one-dimensional array of objects that is immutable meaning once it is assigned it cannot be changed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

tuple functions

A
  • count(item)
  • index(item)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

tuple syntax

A

()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

set syntax

A

{}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

set definition

A

an un-ordered, one-dimensional array of object
- can’t index items
- set is mutable BUT set data is immutable
- set data is unique - no duplicates
- does not all have to be of the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

set functions

A
  • union(setB)
  • intersection(setB)
  • difference(setB)
  • add(item)
  • discard(item)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

dictionary definition

A

ordered, one-dimensional array of key:value pairs
- the key is immutable & can be used to index values in the dict

17
Q

dict functions

A
  • clear()
  • get(key)
  • items()
  • keys()
  • pop(key)
  • values()
18
Q

break

A

immediately exits a loop

19
Q

continue

A

jump directly to the while statement

20
Q

else

A

excuted once the loop ends

21
Q

parameteres of in range()

A

in range(start, stop, loop)

22
Q

list comprehension

A

newlist = [expression for item in data_structure if logical_condition]

23
Q

statement to strip and and read a file

A

list = [line.strip(“ “) for line in list]

24
Q

docstring definition

A

first statement in a module, function, class ore method definition

25
docstring syntax
""" Definition Args Returns """
26
3 types of parameters
1. by position only with 2. by position or keyword 3. by keyword only
27
position-only parameters
- parameters placed before a / - can be helpful in cases where the order of the arguments are more important than their names
28
keyword-only parameters
- parameters placed before a * - can be useful to enforce the use of keyword arguments for certain parameters, such as optional parameters with a default value OR - to clearly distinguish between mandatory and optional arguments
29
optional arguments
- parameters without a default value are required - when defining a function, required parameters need to be specified before the optional ones - useful in combination with keyword arguments to specify exactly which parameter to provide a value each time a function is called
30
args
a tuple & contains all non-keyword arguments passed in when the function is called
31
*args
variable amount of arguments
32
**kwargs
variable amount of arguments formatted as dictionary
33
recursive function characteristics
1. must have a base case 2. change the arguments & more towards a base case 3. call itself
34
statement to open a file
with open("path/to/thefile.txt", "r") as file:
35
w for opening files
write - overwrite the current contents
36
a for opening files
append - add onto the current contents