Section 1: Computer Programming and Python Fundamentals Flashcards
(30 cards)
What is an interpreter?
A program that executes code line by line without producing a separate compiled file.
What is a compiler?
A program that translates source code into machine code before execution, producing a separate executable.
What is lexis in programming?
The set of valid characters and tokens (e.g., keywords, identifiers, operators).
What is syntax?
The rules that define the correct arrangement of tokens in code (grammar).
What is semantics?
The meaning behind syntactically correct code.
What are keywords in Python?
Reserved words with special meaning (e.g., if, else, while, def, return); can’t be used as variable names
What is an instruction in Python?
A complete command for the interpreter (e.g., x = 5, print(“Hello”)).
Why is indentation important in Python?
Indentation defines code blocks and must be consistent (typically 4 spaces).
How do you write a comment in Python?
Use the # symbol for single-line comments and “”” for doc strings
What is a Boolean literal?
True or False
Give an example of an integer and a float in Python.
Integer: 42, Float: 3.14
What is scientific notation in Python?
A way to write large/small floats: 3.5e4 means 35000.0
What are the bases of the numeral systems used in Python?
Binary: base-2 (0b101)
Octal: base-8 (0o12)
Decimal: base-10 (10)
Hexadecimal: base-16 (0xA)
How do you define a string in Python?
Enclose characters in single ‘ or double “ quotes: ‘hello’, “world”; Can also include escape characters with a / in front
What are the rules for naming variables in Python?
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
What does PEP-8 recommend for naming variables?
Use lowercase with underscores: my_variable_name
What are Python’s numeric operators?
**, *, /, %, //, +, -
What are string operators in Python?
+ (concatenation): “a” + “b” → “ab”
* (repetition): “a” * 3 → “aaa”
What are shortcut assignment operators?
+=, -=, *=, /=, %= etc.
What are unary and binary operators?
Unary: operate on one operand (e.g., -x, not x)
Binary: operate on two operands (e.g., x + y)
What determines operator priority in Python?
Exponents: **
Unary: +1, -1, ~1
*, /,//,%
+,-
Bitwise shift: <<, >>
Bitwise and:&
Bitwise xor: ^
Bitwise or:|
==, !=, <, >, <=, >=
not
and
or
=
List some bitwise operators.
NOT: ~
AND: &
OR: |
XOR: ^
Left shift: «
Right shift:»_space;
What are the Boolean operators in Python?
not, and, or
Give examples of relational (comparison) operators.
==, !=, >, >=, <, <=