Namespaces: Python vs C#
Thu, 29 Jan 2026 00:01:04 GMT
BitsNamespaces are set of names used to identify and refer to objects in a project. It ensures that all of a given set of objects have unique names so that they can be easily identified. The word namespace is made up of two words:name — this refers to a name or unique identifier.space — this signifies the scope or accessibility.Namespaces helps the interpreter or compiler understand what exact method or variable one is trying to point to in the code.Let’s use an example to explain this; imagine a room full of members of the Li family. If you want to identify a member whose first name is John, it will be easy because there’s just one person named John Li in that family (assuming all members have unique first names). However if John is in a city, it is likely to have many persons with that first name. So if you are looking for a person whose first name is John in the city, you will have multiple persons with that name but only one person will bear John Li (assuming we have unique family names in the city).Hence within the namespace of the Li family, just “John” is enough to identify this person, but within the “global” namespace of the city, the full name must be used.C# vs PythonLet’s consider this C# code, say you declare a variable age twice in the same namespaceusing System;namespace Person{ public class Program { public static void Main(string[] args) { int age = 5; int age = 34; Console.WriteLine($"Age: {age}"); } }}If you run this program, you will get the following error: A local variable or function named ‘age’ is already defined in this scope.We can fix this by using multiple namespaces:using System;namespace A{ public class Age1 { public static void func() { int age = 5; Console.WriteLine($"Age: {age}"); } }}namespace B{ public class Age2 { public static void func() { int age = 34; Console.WriteLine($"Age: {age}"); } }}namespace Person{public class Program{ static void Main(string[] args) { A.Age1.func(); B.Age2.func(); }}}If you execute this code, you will get the correct output:Age: 5Age: 34You see that you can use namespaces in C# to prevent conflict between types that have the same name.However in Python, you can use the same variable name to refer to different objects but the last variable declaration overrides the previous as seen here:age: int = 6age: int = 78age: int = 19If you run print(age), you will get the last value 19 because it overrides the previous. This also applies to functions:def foo(): return "bar"def foo(): return "baz"In this case, print(foo()) will return baz because the second function overrides the first.One way to avoid this behavior in Python is by using modules and packages. A module is a Python file containing Python codes. You can use the same function name in different modules without one overriding the other because they are in different scopes. Arranging your codes in modules is a good practice that promotes clean-coding and modularity
You built something? Just Push!!!
Mon, 27 Oct 2025 10:02:55 GMT
I have seen many persons make this subtle mistake whilst learning how to write computer programs — they keep writing codes that live only on their devices. They watch video tutorials, read books or other textual resources and practice what they have learnt — which is a great first step.However if you don’t push what you have to an online repository or even take a step further to deploy it to a live server, you would have just written perhaps clean codes that only stays on your machine.Software Engineers don’t just write codes, they are problem solvers willing to share their solution to the world. A good developer is open to constructive only feedback, and is not afraid to try new approaches in problem solving. He is not bothered about code reviews if done professionally.After developing a solution to a problem perhaps with pseudocodes or illustrations, the engineer then implements that solution (algorithms) with codes. The original solution is usually not perfect but the engineer, knowing that it can be improved on pushes it for others to see, critique or even contribute to. This cycle of refinement continues in an agile manner until the software meets the expectation of the users.Now imagine if the developer never pushed that code or was waiting for it to be perfect first, it would have undoubtedly remained on his system — visible only to him. If you are learning a programming language and have built something — no matter how small, get a GitHub or GitLab account and push it there. Be bold and fearless enough to ask more experienced developers to review your codes and don’t forget to continually improve your solutions.Lastly, seek mentorship from professionals — this is the fastest way to learn anything in life.Happy Coding!
How I use Python to read my Bible
Mon, 20 Oct 2025 10:26:30 GMT
Whenever I find myself needing to do some arithmetic operations, my go-to calculator is not the built in calculator app on my mobile device or PC but a Python REPL. This perhaps is an effect of working with Python daily. I find it easier to perform everyday tasks from my Python shell.For example, when reading my favorite book — The Bible, my Math sense often wants to know if the sum of numbers from a census actually corresponds to what is written. For this, I often use a calculator to verify the sum. My Python REPL helps me do this seamlessly. For instance, whilst reading Numbers 1, I wanted to verify that the total number of men twenty years old or older who were able to go to war as counted actually adds up to 603,550 as stated in Numbers 1:45–46.For this I used a Python dictionary to store data in key, value pairs. The keys being the names of each tribe of Israel and the values their corresponding count as recorded in scriptures:Using Python’s built-in sum() function to add the values shows that it does correspond ✅.I used type hints in the REPL (imported more than I needed ❌), knowing that Python’s REPL does not currently enforce type checking ⚠️. However I predict that in the future, the standard Python REPL may offer support for this — perhaps offering an option to toggle between strict type checking or not 🤷♂️.This is just one of the ways I use Python in my day to day life whenever I’m not coding. Let me know how you use Python daily.
Setup your Learning Environment
Mon, 09 Sep 2024 12:58:01 GMT
Python is free and easy to learn. It can be used in learning Mathematics and sciences. The first step would be to setup your learning (programming) environment.You would want to install the Python 3 interpreter on your machine. It reads Python codes and execute the instructions. You cannot run your Python code without it.Python comes pre-installed on many computers. To verify if Python is on your computer, run the python command. This will launch the Python interpreter if you already have it installed. On windows you can use the py command. If it is installed, you will get a response giving you the version number and other details:Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.If you don’t get this response, you will need to install Python on your computer.Sometimes, Mac and Linux distributions may come with Python 2. This is an old version of Python and is no longer maintained. It is recommended that you install Python 3. If you do not have Python on your machine or you want to upgrade to a recent version you can visit:https://www.python.org/downloads/and download and run the installer for your specific machine. You can visit the Python documentation if you need a detailed guide on how to install and setup Python:Python Setup and Usage — Python 3.12.5 documentationYou can now run the python command to verify that it is now installed on your computer.
Hosting your Python app on PythonAnywhere?
Mon, 01 Dec 2025 23:38:49 GMT
PythonAnywhere is a cloud-based environment that enables users to develop and host Python applications directly from their browsers.As a Python developer, I continue to use PythonAnywhere to host my Python apps. It has become my favorite hosting tool and when teaching Python in bootcamps, I often guide my students to deploy their apps to PythonAnywhere. They provide a very generous fremium which is sufficient if one is just building a portfolio app or a lightweight web app. As you scale, you might have to migrate to a paid plan. I have used the free plan extensively and have also used the paid plan to host the MVP of the company I work for.There are however some limitations on the free plan; PythonAnywhere states that “Free accounts’ internet access goes via a proxy “allowlist”; they can only access sites that are on that list.” This is done to prevent malicious users from using their site to hack into and spam other websites. Paid-for accounts don’t have this limitation, because they can be mapped to real humans. On the other hand, spammers and criminals prefer to be anonymous and are unlikely to sign up for paid accounts on PythonAnywhere.When I wanted to pull my medium feeds on my Django app, I discovered it was working well on localhost but was not parsing in the live app on PythonAnywhere. So I had to write them to whitelist the domain name *.medium.com which they graciously did. You can find the list of sites currently allowed on PythonAnywhere here and you can use this form to request an addition to the allowlist.Happy Hosting!
Running Source Code in a plain text file
Fri, 30 Jan 2026 19:38:24 GMT
Note: This article is for information purposes only. I do not recommend using plain text editors or word processors for writing source codes.Text Editors, Code Editors and IDEsText editors are applications used in writing and editing text files. They are lightweight and do not perform complex formatting on words like Word processors (e.g. Microsoft Word). You can use any text editor or even Microsoft Word to write Computer programs but this is not recommended because a code editor or Integrated Development Environment (IDE) is often used in practice. Codes written in text editors or word processors risk being corrupted. Besides this, you will also miss out on certain benefits of using modern IDEs.A code editor is used in writing and editing source code. An IDE extends this functionality by combining code editors with essential developer tools such as compilers/interpreters and debuggers in a single application thereby streamlining software development. This improves developer productivity by automating tasks, providing syntax highlighting, enabling code completion amongst other benefits. Some examples of popular IDEs are Visual Studio, Visual Studio Code, Sublime Text, and PyCharm.Most professional software developers write programs with a relevant IDE or Code Editor. However we will write a basic Python program in plain Notepad and save it as a .txt file instead of .py file.Note: I am using Notepad because I’m working with a Windows machine. What matters is not the software I used in creating a .txt file. If you are on MacOs or any other OS, feel free to use any other text editor that works for you.We are going to write a simple program that iterates over a list of fruits and displays each fruit. The first thing we will do is to create a file for our source code, in this case our .txt file. Please note that we will use a text file instead of a Python (.py) file to demonstrate this.Go to your desktop and create a file fruits.txt. Open the file and enter the following:from typing import Listfruits: List[str] = [ 'guavas', 'apples', 'cucumbers', 'blueberries', 'grapes', 'oranges', 'bananas' ]for index, fruit in enumerate(fruits, 1): print("{0}. {1}".format(index, fruit))Save changes to your file. Next we will spin up our Command Prompt or Terminal and enter the following command to get into the location of your file:cd desktopthen run the program using this command:python fruits.txtIf there are errors in your code, you will see the error message output in the Terminal. If this happens, revisit the steps and example used here and ensure you are not missing anything. If your work looks exactly like mine, your program will run and the list of fruits will be nicely displayed:1. guavas2. apples3. cucumbers4. blueberries5. grapes6. oranges7. bananasThis is a simple example of how we can write Python programs in .txt files. What do you think will happen if we tried to import this “module” into a Python file? Let me know in the comments.
Using Python, get the Numbers whose Square root or Cube root is equal to the sum of its digits…
Fri, 07 Nov 2025 00:52:36 GMT
Using Python, get the Numbers whose Square root or Cube root is equal to the sum of its digits minus 2 or 3 respectivelyhttps://vm.tiktok.com/ZSHcqsxwYcD9V-BqX0C/I have been so engrossed in work — using Python for web development that I hadn’t made time as I used to - for solving Math problems with Python.Today I came across an interesting rule that works for a few perfect squares and perfect cubes. Get the numbers that match if the sum of their digits minus two equals the square root of the number or if the sum of their digits minus three equals the cube root of the number.I wrote this program to solve this problem in Pythonfrom math import sqrt, cbrtdef add_nums(num): """Return the sum of digits in a number.""" if isinstance(num, int): str_num = str(num) res = [int(i) for i in str_num] return sum(res) return f"{num} is not a valid integer."def square_nums(n): """ Check whether the sum of digits of a number minus 2 equals the square root of that number. Return the list of numbers that match. """ lst = [] for i in range(n): if sqrt(i) == float((add_nums(i) - 2)): lst.append(i) return lstdef cube_nums(n): """ Check whether the sum of digits of a number minus 3 equals the cube root of that number. Return the list of numbers that match. """ lst = [] for i in range(n): if cbrt(i) == float((add_nums(i) - 3)): lst.append(i) return lst# Run programdecision = input("Enter 's' to check for square roots and 'c' for cube roots: ")n = int(input('Enter a non-negative integer: '))if decision == 's' or decision == 'S': print(square_nums(n))elif decision == 'c' or decision == 'C': print(cube_nums(n))else: print('Invalid entry')What do you think about this solution? Do you have a better way of solving this?PS: Whilst solving this, I discovered that Python’s `math` module now has the `cbrt` function since Python 3.11+. Last time I wanted to use cube root in Python, it wasn’t available and I had to rely on the `pow` function.