Junior Programmer study materials
Junior Programmer study resources

Junior Programmer: Programming Fundamentals: Syntax, Variables, Data Types, Operators, and Expressions

Junior Programmer · Work through your exam, one topic at a time.

All guide sections

Programming Fundamentals: Syntax, Variables, Data Types, Operators, and Expressions

Programming fundamentals is the domain every other section depends on: how a program's text becomes valid statements, how values are stored and typed, and how operators combine those values into expressions. The exam asks you to read a short snippet and predict its output, identify a syntax error, and explain why a type mismatch or precedence rule produced a given result.

Variables, types, and assignment

A variable is a name bound to a value. Declaration creates the name; assignment rebinds it. Know the difference between statically typed languages (the type is fixed at compile time) and dynamically typed ones (the type travels with the value). Integers, floats, booleans, characters, and strings behave differently under the same operator: 7 / 2 is 3.5 in Python but 3 in Java when both operands are int. Strings are immutable in most languages, and concatenating a string with a number usually requires an explicit conversion.

Operators and expressions

Arithmetic operators follow precedence: parentheses, then exponentiation, then multiplication, division and modulo, then addition and subtraction. Comparison operators return a boolean; logical and/or short-circuit left to right. Assignment (=) and equality (==) are different operations, and using the wrong one is a classic syntax or logic error. Modulo keeps the sign of the divisor in Python, which surprises people.

Worked example

a = 7
b = 2
print(a / b)        # 3.5
print(a // b)       # 3
print('Total: ' + a)

Line 1 uses true division because / on two numbers returns a float. Line 2 uses floor division, discarding the remainder. Line 3 raises TypeError: + is defined for str+str, not str+int. The fix is 'Total: ' + str(a) or an f-string.

Traps

  • Writing if x = 5: instead of ==.
  • Assuming / is integer division in every language.
  • Forgetting that and/or may return an operand, not a boolean, in Python.
  • Overflow or truncation when a float is cast to int.