Section 1: Computer Programming and Python Fundamentals Flashcards

(30 cards)

1
Q

What is an interpreter?

A

A program that executes code line by line without producing a separate compiled file.

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

What is a compiler?

A

A program that translates source code into machine code before execution, producing a separate executable.

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

What is lexis in programming?

A

The set of valid characters and tokens (e.g., keywords, identifiers, operators).

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

What is syntax?

A

The rules that define the correct arrangement of tokens in code (grammar).

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

What is semantics?

A

The meaning behind syntactically correct code.

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

What are keywords in Python?

A

Reserved words with special meaning (e.g., if, else, while, def, return); can’t be used as variable names

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

What is an instruction in Python?

A

A complete command for the interpreter (e.g., x = 5, print(“Hello”)).

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

Why is indentation important in Python?

A

Indentation defines code blocks and must be consistent (typically 4 spaces).

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

How do you write a comment in Python?

A

Use the # symbol for single-line comments and “”” for doc strings

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

What is a Boolean literal?

A

True or False

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

Give an example of an integer and a float in Python.

A

Integer: 42, Float: 3.14

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

What is scientific notation in Python?

A

A way to write large/small floats: 3.5e4 means 35000.0

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

What are the bases of the numeral systems used in Python?

A

Binary: base-2 (0b101)
Octal: base-8 (0o12)
Decimal: base-10 (10)
Hexadecimal: base-16 (0xA)

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

How do you define a string in Python?

A

Enclose characters in single ‘ or double “ quotes: ‘hello’, “world”; Can also include escape characters with a / in front

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

What are the rules for naming variables in Python?

A

Snake case for standard variables:
Start with a letter or underscore
Can include letters, numbers, and underscores
Caps case for constants:
All uppercase letters and numbers seperated by underscores
Cannot be a keyword
Case-sensitive

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

What does PEP-8 recommend for naming variables?

A

Use lowercase with underscores: my_variable_name

17
Q

What are Python’s numeric operators?

A

**, *, /, %, //, +, -

18
Q

What are string operators in Python?

A

+ (concatenation): “a” + “b” → “ab”
* (repetition): “a” * 3 → “aaa”

19
Q

What are shortcut assignment operators?

A

+=, -=, *=, /=, %= etc.

20
Q

What are unary and binary operators?

A

Unary: operate on one operand (e.g., -x, not x)
Binary: operate on two operands (e.g., x + y)

21
Q

What determines operator priority in Python?

A

Exponents: **
Unary: +1, -1, ~1
*, /,//,%
+,-
Bitwise shift: <<, >>
Bitwise and:&
Bitwise xor: ^
Bitwise or:|
==, !=, <, >, <=, >=
not
and
or
=

22
Q

List some bitwise operators.

A

NOT: ~
AND: &
OR: |
XOR: ^
Left shift: «
Right shift:&raquo_space;

23
Q

What are the Boolean operators in Python?

24
Q

Give examples of relational (comparison) operators.

A

==, !=, >, >=, <, <=

25
Why are floating-point numbers not always accurate?
They are stored as binary approximations, which can lead to rounding errors.
26
What is type casting in Python?
Converting one data type to another, e.g., int("5"), float(3)
27
What does print() do in Python?
Outputs text or variables to the console.
28
What does input() do?
Outputs a message to the user and takes user input as a string
29
What do sep= and end= do in print()?
sep: specifies the separator between printed values (print("Hello","world",sep="-")) # prints "Hello-world" end: specifies what to print at the end (default is \n)
30
How do you convert user input to an integer or float?
int(input()) float(input())