Skip to content

Python Features That May Be Unfamiliar to C/Java Programmers

(Quick reference)

Python was designed with simplicity and readability in mind. As a result, it differs from traditional programming languages such as C, C++, Java, and JavaScript in several ways. This section highlights some of the most notable differences.


1. No Traditional switch Statement

Older versions of Python do not have a switch statement. Instead, they use if-elif-else.

day = 3

if day == 1:
    print("Monday")
elif day == 2:
    print("Tuesday")
elif day == 3:
    print("Wednesday")
else:
    print("Unknown")

Starting with Python 3.10, Python introduced match-case, which provides functionality similar to a switch statement while supporting more advanced pattern matching.

day = 3

match day:
    case 1:
        print("Monday")
    case 2:
        print("Tuesday")
    case 3:
        print("Wednesday")
    case _:
        print("Unknown")

2. No Curly Braces

Most programming languages use curly braces ({}) to define code blocks. Python uses indentation instead.

C / Java

if (x > 0) {
    printf("Positive");
}

Python

if x > 0:
    print("Positive")

Consistent indentation is mandatory in Python.


3. No Semicolons

Statements do not require semicolons.

x = 5
y = 10
print(x + y)

Although semicolons are allowed, they are rarely used.


4. Dynamic Typing

Variables do not require explicit type declarations.

C

int age = 20;
float price = 9.99;

Python

age = 20
price = 9.99

Python automatically determines the data type at runtime.


5. Everything Is an Object

In Python, nearly everything is an object, including integers, strings, functions, and classes.

x = 5
print(type(x))

Output:

<class 'int'>

6. No ++ or -- Operators

Python does not support increment or decrement operators.

C

i++;
++i;
i--;

Python

i += 1
i -= 1

7. No do...while Loop

Python does not include a do...while loop.

C

do {
    printf("Hello");
} while (x < 5);

Python Equivalent

while True:
    print("Hello")

    if x >= 5:
        break

8. Different for Loop

Traditional languages typically use a counter-controlled loop.

C

for (int i = 0; i < 5; i++)

Python

for i in range(5):
    print(i)

The expression range(5) generates:

0 1 2 3 4

9. Lists Instead of Arrays

Python's built-in collection is the list, which is dynamic and flexible.

numbers = [1, 2, 3]
numbers.append(4)

Lists can also contain different data types.

items = [1, "hello", 3.14, True]

10. Multiple Assignment

Python allows multiple variables to be assigned in one statement.

a, b = 5, 10

Variables can also be swapped without using a temporary variable.

a, b = b, a

11. Easy Iteration

Instead of looping through indexes, Python usually iterates directly over elements.

Instead of:

for i in range(len(names)):
    print(names[i])

Use:

for name in names:
    print(name)

If both the index and value are needed:

for index, name in enumerate(names):
    print(index, name)

12. List Comprehensions

Python provides concise syntax for creating lists.

Traditional approach:

squares = []

for x in range(10):
    squares.append(x * x)

Using a list comprehension:

squares = [x * x for x in range(10)]

13. Functions Can Return Multiple Values

A function can return more than one value.

def divide(a, b):
    return a // b, a % b

quotient, remainder = divide(10, 3)

14. No Mandatory main() Function

Python programs execute from top to bottom.

print("Hello")
print("World")

For larger programs, the following convention is commonly used:

def main():
    print("Hello")

if __name__ == "__main__":
    main()

This is optional but considered good practice.


15. Rich Built-in Data Structures

Python includes several powerful built-in data structures.

# List
numbers = [1, 2, 3]

# Tuple (immutable)
point = (2, 5)

# Set
unique = {1, 2, 3}

# Dictionary
student = {
    "name": "Alice",
    "age": 20
}

16. Functions Are First-Class Objects

Functions can be assigned to variables and passed as arguments.

def greet():
    print("Hello")

f = greet
f()

This enables powerful programming techniques such as callbacks and higher-order functions.