Week 1 Flashcards

1
Q

What are values in programming?

A

A specific piece of data or information that a program can use, store, manipulate, or pass around.

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

What are expressions in programming?

A

A combination of values, variables, operators, and functions that can be evaluated or computed to produce another value

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

What are statements in programming?

A

A single instruction or command that a program executes.

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

What is an interpreter in Python?

A

A program that reads a high level programming language and executes the instructions one line or statement at a time.

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

What is the correct way to format floating point numbers in a print statement?

A

Print(f”{e:.#f}”)
With # as the number of decimal places

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

What function is used to get user input?

A

The input() function

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

What function is used to convert strings to integers?

A

The int() function

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

What function is used to convert strings to floating point numbers?

A

The float() function

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

What operator is used to do floor division?

A

The // operator

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

What does _ mean in python?

A

It is a variable representing the last printed expression

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

Are strings considered mutable or immutable?

A

Immutable

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

What built in objects are considered false?

A

Constants “None” and “False”
Zero of any numeric type
Empty sequences and collections

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

Do comparison or Boolean operators have higher priority?

A

Comparison operators

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

What are the three distinct numeric types?

A

Int, float, complex

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

How are constants formated in Python for CS 111?

A

Upper snake case

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

How to you run a doctest in the terminal?

A

With the command “python3 -m doctest file.py” executed in the correct directory

17
Q

How do you run a pytest in the terminal?

A

With the command “python3 -m pytest -vv” in the correct directory

18
Q

What does “python -i file.py” do?

A

It runs your code and opens an interactive session

19
Q

Order the Boolean operators in order of priority:

A
  1. Not (highest)
  2. And
  3. Or (lowest)
20
Q

What values are considered truths values?

A

True, non-zero integers, etc.

21
Q

What values are considered false values?

A

False, 0, None, [], etc.

22
Q

How do you “unpack” multiple return values from a function in Python?

A

a, b, … = function(argument, argument, …)

23
Q

Cs50P: How can you open two files at once with the “with” statement?

A

Use a comma to separate the statements:

With open(…) as file, open(…) as file2:

24
Q

What is a call expression?

A

It applies a function which may or may not accept arguments

25
Q

What is a call expression?

A

It applies a function which may or may not accept arguments

26
Q

How do you use slicing in Python?

A

name[start:end:step_size]

27
Q

Does slicing include or exclude the beginning and end?

A

Includes the beginning, excludes the end

28
Q

Does slicing include or exclude the beginning and end?

A

Includes the beginning, excludes the end

29
Q

Does slicing include or exclude the beginning and end?

A

Includes the beginning, excludes the end

30
Q

What are comprehensions?

A

A compact and powerful way of creating new lists out of sequences

31
Q

What is the simplest syntax for a list comprehension?

A

[expression_to_add for element in sequence]

32
Q

How do you reverse a string with slicing?

A

Reversed_string == string[::-1]

33
Q

How would you modify a golobal variable in a function?

A

With the global variable: global x

34
Q

What does the extend() function do in Python?

A

It is used to add items from one list or iterable to the end of another list

35
Q

What is best practice for handling close for a file that may raise an exception?

A

try:
file = open(“filename.txt”, “r”)
finally:
file.close()