Install Interpreter
First things first, Python is a high-level programming language. It is interpreted by a python interpreter. You can get the latest interpreter at https://www.python.org/downloads/.
Once you download one specific to your computer operating system, install it and remember to add it to the path. To check if Python is installed, open the command line, type the below command, and press enter. Thus, you will see the installed Python version.
python --version
IDE
To create python scripts, you can use any text editor and save files with a .py extension. That way you can run it from the command line though I encourage you to make life easy for yourself by either using IDLE or Visual Studio Code among many existing IDEs. IDLE comes with a Python interpreter so search for it on your machine. Visual Studio Code is found at https://code.visualstudio.com/download. Download one suitable for your operating system and install it.
After installing your IDE, open it, create a new Python file, name it, "introduction.py"
Type the following code,
print( "Hello, World" )
Run it, and you will see the below output on the console.
Hello, World
Congrats on your first program. Keep rolling! By the way, for now, we are writing console-based programs. As you go through the following sections of the article, write the code in the file you created above.
Press "Enter" to get to a new line where you can declare your variables.
Identifier vs Variable
Enough of the talk, let's dive into programming. As you code, you need to give different types of entities some names. The entities given identifiers can be variables functions, classes, and lists which we shall look at later. All these are objects. Having said this, identifiers must be meaningful.
A variable is a named memory location where a value is stored. It is a method of referring to a value stored in memory for later use in the program. When a variable is given a value, that value is stored in memory, and the identifier is used to refer to that memory location.
NB: We should store a value in a variable when we need to access or modify that value multiple times in our code, or when the value is complex and difficult to calculate or remember.
Many of the programs we develop are problem oriented. They are meant to solve problems. At some moments input data is given to the program through hard coding, i.e. programmer determines values in advance by creating variables assigned to values of many data types.
name = "James"
Rules for identifiers
A data type is a type of data. E.g. String, Boolean, Float, and Integers among others. In Python, all these are objects but will talk later about that. Unlike other programming languages, python needs no type declarations. Python interpreter dynamically allocates objects or data types based on the value on the right side of the assignment operator.
An assignment operator, "=" is used to assign what is on the right of = to a variable name on the left of it. In Python Programming, variables are declared together with initialisation, where we assign values to variable names. Below are examples of declaring variables and assigning different data types to them.
NB: Only store values that you need to reuse in your program.
Integer (int): A whole number e.g.
age = 34
Float ( float): A real number or decimal value e.g.
height = 1.65
Boolean (bool): Values that represent either True or False e.g.
complete = True
finished = False
message = "Hello World"
Anything in quotes is a string. e.g "1" , "[5,6,4]" . Though 1 and [5,6,7] are integers and lists respectively when put inside quotes they are taken literally as strings, not as their original data types outside quotes. The brackets, and numbers in "[5,6,4]" just become elements of the string not related in any way.
num_list =[1, 2, 3]
num_turple =(1, 2, 3)
num_set ={1, 2, 3}
person = {'name': 'Peter', 'age': 43, "job": "developer"}
city, code = "Chiredzi", 1
print("Code before overwrite", code)
code = 2
print("Code after overwrite", code)
Product of
Jeremiah Taguta T/A Charis Technologies