Now that you’ve successfully set up your Python environment using Docker, it’s time to delve into the fascinating world of computer programming. In this section, we’ll explore the foundational concepts that form the backbone of programming knowledge.

Evolution of Programming Languages

The journey of computer programming has been marked by remarkable evolution over the years. It all began with machine language, a cryptic world of binary code consisting of 0s and 1s. As the years passed, programming languages evolved, and one significant milestone was Assembler. This lower-level language relied on symbols and concise commands, simplifying low-level computer operations.
Today, we work with modern, human-readable programming languages that have made the process of coding more accessible and efficient.

Programming Paradigms

With the emergence of these modern languages came different programming paradigms, each with its unique approach. Two of the most prominent paradigms are Structured Programming and Object-Oriented Programming (OOP). Let’s take a brief look at each of them:

Structured Programming:

  • Structured programming is all about breaking down a program into smaller, manageable functions or procedures.
  • It follows a linear or top-down approach, ensuring a clear sequence of execution.
  • This paradigm is renowned for its simplicity and is well-suited for smaller, less complex applications.

Object-Oriented Programming (OOP):

  • OOP is centered on the concept of “objects,” which represent instances of classes or templates encapsulating data and behavior.
  • It encourages organizing code around objects and their interactions, simplifying the modeling of real-world entities.
  • OOP languages like Java, C++, and Python facilitate the creation of reusable and modular code through classes and objects.
  • It excels in handling complex applications, allowing the modeling of real-world entities and their relationships effectively.

Common Programming Constructs

Both structured programming and OOP share fundamental programming constructs that are essential to your programming journey. These include:
Sequence: The concept of sequence is straightforward – each line of code follows the next, executing in a predictable order. In your “lesson1” folder, create a “sequence.py” file to explore this concept further, running it with the command docker-compose run my-environment python sequence.py either from the command line, or your VS Code terminal.
# In Python, text preceded by a # becomes a comment. Comments are used for documentation and are ignored during code execution.
a = 1  # Comments can also appear after a line of code. Here, "a" is a variable with a value of 1.
b = 2
print("a = " + str(a))  # Text can be built up in Python using the + symbol; this is known as concatenation.
print("b = " + str(b))
c = a + b
print("a + b = " + str(c))
# It's important to note that text is considered a string, while numbers are of various types (e.g., integers).
# Mixing data types can yield unexpected results. For instance, 1 + 2 = 3, but "1" + "2" = "12."
# To concatenate different data types using the + sign in Python, we typically use the str() function to convert integers to strings
Repetition: Repetition, often referred to as looping, is a fundamental concept that enables the execution of a specific block of code multiple times. In this section, we’ll focus on the “While” Loop, but rest assured, we’ll delve into other looping constructs in subsequent lessons. Create a “repetition.py” file to experiment with this concept, running it with the command docker-compose run my-environment python repetition.py either from the command line, or your VS Code terminal.
# Demonstrating the application of a while loop to count from 0 to 19
# It is important to emphasize that in programming languages, delineating the boundaries of code blocks is imperative.
# In Python, we signify the commencement of a block by concluding the preceding line with a colon (:) and then aligning all the code within the block with a four-space indentation.
count = 0
while count < 20:
    print(count)
    count += 1  # Incrementing the count by 1 during each iteration. This is equivalent to count = count + 1.
Selection: Selection involves decision-making and executing specific code blocks based on particular conditions. It adds flexibility and responsiveness to your code’s behavior. Create a “selection.py” file to practice this concept, running it with the command docker-compose run my-environment python selection.py either from the command line, or your VS Code terminal.
# Demonstrating the application of an "if" statement to determine if a number is even or odd
# In programming, "if" statements are employed to evaluate conditions and execute specific code blocks based on the outcome.
# In most languages, the % operator, known as modulus, returns the remainder of a division operation.

number = 7  # You can modify this number to observe different results
if number % 2 == 0:  # Note the use of ==; it's used for value comparison, while a single = is for assignment.
    print(f"{number} is even.")  # In Python, f-strings provide an elegant way for string concatenation and handle datatype conversion automatically when possible.
else:
    print(f"{number} is odd.")

Congratulations

Congratulations on embarking on this programming journey! You’ve already explored foundational concepts like sequence, selection, and repetition, and gained valuable insights into topics such as variables, data types, code blocks, and concatenation.
Now, it’s time for a well-deserved break to recharge. When you’re ready, join us again as we delve into the intriguing world of objects in programming. Remember, you can work through these steps at your own pace, and if you have any questions or encounter challenges, we’re here to help.
Founder & Principal at Daptl | peter@daptl.com | Website | + posts

Nova Scotia-based software developer with a rich history in entrepreneurship and technology. In the year 2000, embarked on a collaborative journey to automate statistical data gathering for a hockey pool, which later evolved into a thriving business focused on curating sports statistics.

Through strategic contracting in various sectors, including telecommunications and insurance, contributed to the growth of the startup, eventually expanding it to a significant enterprise with over 100 employees and worldwide affiliates.

Now, in the phase of semi-retirement, founded 'Daptl' to explore new contracting opportunities, adding another chapter to an already impressive career.

Related posts