Hi!
We are going to tackle the following topics in Python briefly, just to help you catch a glimpse of what you are going to face when you start using Python.
- Introduction
- Variables and datatypes in Python
- Operators in Python
- Control structures
- Arrays
i. Introduction
Python is a high-level programming language that is used for educational purposes and also to solve real world IT related problems.
It is considered to be a very easy language to learn, understand and implement. If you are hearing of programming for the first time and you want to unleash your programming passion, this is your to go language. If on the other hand you have been on the field for a long time, you will grasp Python very quickly and with no time you are doing wonders.
Fan facts about Python
- It is a popular language applied across to solve various IT problems. So you won’t be wasting your time learning Python.
- It has a very simple syntax therefore you will never be intimidated about how to maneuver around as you develop your application.
- With the simple syntax in play, you don’t have to have numerous classes or pages of code in your application for it to be called a serious application. Just few working lines and you have solved a huge problem. Brains and it’s supported by Windows, Linux and MacOS Operating systems.
- Sublime text (Text editor) – it is a generic text editor for variety of language and super simple to use. It is fast and helps in debugging of code efficiently. It’s supported by Windows, Linux and MacOS Operating systems.
- Visual Studio Code (IDE) – it is a powerful code management engine that was developed by Microsoft for platforms like Windows, Linux and MacOS Operating systems.
- Vim(Text Editor) – it provides a good user experience when coding and enriched with different features that aid in development.
ii. Variables and Datatypes in Python
We have talked about the simplicity of Python. Now at this point we start to explore the first simple fact about Python.
We do not explicitly declare variables with their datatypes. Python assigns a datatype depending with the data you are assigning that variable.
- Type of variables Local variables – these are those used inside a function or a method Global variables – they are used when you want to use a variable on the entire program. The various datatypes are:
- Integer – for storing numerical values, wholes number
- Floating point – for storing decimal numbers
- Strings – for storing text or any data that is enclosed using double quotes (“ ”).
- Booleans – this stores either true or false depending on what an expression will return. There are other datatypes that maybe a bit advanced for beginners but will be tackled later. iii. Operators in Python Operators are simply actions or process that instruct the complier on what to do on a predefined set of data. Types of operators
- Arithmetic operators
- Assignment operators
- Comparison operators
- Logical operators Most likely you will encounter scenarios that will require you to use either of these types of operators stated above. Let’s have a brief insight about each of them.
- Arithmetic operators – these operators are used to perform basic mathematical operations. They include: - +,-,*, /, %
- Assignment operators – from the name you can already understand the role of these operators. They are used to assign values to the variables. They include: - ==, -=, +=, =, ++, --, /=, %=, *=
- Comparison operators – these operators are used on two values and they return a Boolean value which is either true or false. They include: - ==, <, >, >=, <=, !=
- Logical operators – there operators are used to combine values that result into Boolean values. They include: - AND, OR, NOT
iv. Control structures in Python
The three different types of control structures are: - Selection, sequential, repetition.
We are going to briefly get an insight on the three structure and try to understand their role in python programming.
- Selection – this structure allows you to take decisions based on a particular criteria. You can used the following statement to archive this:
- If statements – for at least one condition
- If else statements – for at least two conditions
- If else if statements – for more than two conditions
- Sequential – this is where by you have to execute an instruction before going to the next set of instructions. Example finding an average of marks, you have to get the total marks then divide by the number of subjects or units.
- Repetition – this requires that a certain code is repeated until a predefined condition is met. The statements used to archive this control structure are:
- While… loop
- Nested loop
- For loop
- Arrays in python An array is just basically a collection of a set of data with the same characteristics like the datatype. They are used to store multiple values in one single variable. Arrays use an index to access the elements at the specific position. The indexes start from 0 which is equivalent to element 1. The only difference with normal variable naming is that you include a square bracket ([ ]).
Top comments (0)