Python is a powerful and versatile programming language that has gained immense popularity in recent years. Its known for its simplicity, readability and extensive library support thus making it an ideal choice for beginners and experienced developers alike.In this article we will discuss the installation process ,explore its syntax and discuss comment under python.
Overview
python was created by Guido van Rossum and first released in 1991.Its an open source,high level programming language that really emphasizes codes readability and productivity.Its language is designed to be easy to learn and understand,making it an execellent option for those new to programming.
It has a large and active community of developers which has led to a rich ecosystem of libraries and frameworks.Widely used in various domains such as web development,data analysis,artificial intelligence,automation and more.
Installation.
python is available for multiple platforms,including windows,macOS and linux.Here we going to take you through installation of python with window users.
- Visit the official python website and navigate to the download section.
2.choose the appropriate installer for your operating system(python 3.x is the most recommended).
3.Download the installer and run it.
4.During the installation make sure to check the option to add python to the system PATH.This allows you to run python from the command line.
Once the installation is complete,you can open a command prompt and type the following to check the version and whether you installed it right.
what is a syntax
syntax in programming refers to the rules that define the structure and grammar of a programming language.it dictates how statements and expressions should be written to create valid and meaningful code.Here statements are typically written on separate lines, and identation is used to indicate blocks of code.python uses whitespace identation to group code which enhances code readability.
example:
print("Hello World!")
To create your first program first create your folder where you will save your files.Then launch visual studio code then open your created folder in it.There after create a file eg,training.ipynb and enter the above code and save the file.
The above code is mostly the first code most learners start with where python interprets print()function as instruction to display the specified message,and it outputs "Hello World!".
pythons uses built in data types and data structures.
1.Data types --> are categories that define what kind of value a variable can hold and what operations can be performed on it.
_Variables_is a named memory loaction.variables use letters from letters a-z and can contain alphanumeric characters and underscores (a-z,0-9).
You cant use reserved words to present variables.
example;
name = "abdi" # variable name assigned the string value "abdi"
print(name)
We have three different types of data types namely;
1.Numeric type.
2.Text type.
3.Boolean type.
Numeric type-these are classified into three types namely;
- Integers
- Float
- complex numbersIntegers defines a whole number(integers) defined as int
example;
age = 30 # integer data type representing someone's age.
- float its a decimal number in python example;
height = 1.75 # float representing height of a person.
- complex numbers Used for numbers with a real and an imaginary part, written with a j as the imaginary suffix eg,
complex_num = 2 + 3j # complex number with real part 2 and imaginary part 3
2.Text type are mainly which consists of a single built-in class ;str
greeting = "Hello, World!" # string data type representing a greeting message
- boolean are actually a "subtype" of integers. This means you can technically use them in math. examples are listed below;
# boolean logics
true + false = 2 # defines as true
false + 5 = 5 # defines as false
x == y = 10 # defines x and y as equal to 10
x != y # it defines x and y as not equal
x > y # logical comparison to check if x and y are greater than each other
Data structures
data structures in python are a way of storing and organizing data in a computer. we have several data structures;
1.List
They are implemented as dynamic mutable arrays which hold an ordered collection of items.They can contain integers, strings and even functions within it. Different elements of a list can be accesed by integer where the first element of a list has the index of 0.
example;
Games = ["football", "basketball", "Table Tennis", "Rugby"]
print(Games)
print(Games[0])this code will print the first key character in your list above.
Inside the list we can add,remove and change elements inside it.
for instance .append() adds a new element to a list while .remove() an item from a list.
2.Tuples
They are almost identical to lists, so they contain an ordered collection of elements, except for one property: they are immutable.We cannot use them when we have to work with modifiable objects; we have to resort to lists instead.
example;
students_fail=("John", "Alice", "Bob", "Eve")
students_fail = ("John", "Alice", "Bob", "Eve")
print(students_fail)
3.Dictionary
These are mutable data structures that contain a collection of keys and, associated with them, values.They are used to quickly access certain data associated with a unique key.
example;
user_data = {"key1": "value1", "key2": "value2", "key3": "value3"}
print(user_data)
4.Sets
They are an unordered collection of unique elements. Sets are defined using curly braces {} and do not allow duplicate values.
unique_num = {1, 2, 3, 4, 5}
print(unique_num)
Python for data analysis
python ussualy offers powerful libraries specifically designed for analysis.some of them are :
1.pandas - open source Python library used for data analysis, manipulation, and cleaning.They are built in two categories mainly.
a)Series: A one-dimensional labeled array capable of holding any data type.
b)DataFrame: A two-dimensional, size-mutable tabular data structure with labeled axes (rows and columns). It is essentially a collection of Series objects that share the same index.
- NumPy libraries used for numerical computations.
3.Matplotlib &seaborn :Is used for data visualization.
Basic workflow of data analytics with python.
Data collection-it involves extracting data from various sources such as excel,databases,APIs and scrapping the web.
example:
- Here we extract a mock data from
mockaroo.comwebsite for purposes of practising.
import requests
water_billing_url = "https://example.com/water_billing.json"
water_billing_data = requests.get(water_billing_url).json()
print(water_billing_data)
_Data cleaning _ is handling missing data, correcting data types, removing duplicates and filtering irrelevant data.
example:
#data cleaning and manipulation
name = {"name":"George",
"Course": "Data science",
"County": "laikipia",
"Age": 30,
"Nationality": "kenyan"}
print(name)
#append key in the dictionary.
name ["sports"] = "Table tennis"
print(name)
Exploratory data analysis is analyzing data and generating visualizations to identify patterns and to draw insights.
Visualization and reporting are tools and libraries used to create dashboards ,plots and reports.
Learners who wish to kickstart their data analysis journey python is the ideal tool to work on as it has the following advantages compared to other programming languages;
R_eadability and Simplicity_: Python’s syntax is clean and resembles natural English, which reduces the learning curve.
High Productivity: Because it handles complex tasks like memory management (garbage collection) and dynamic typing automatically, developers can focus more on solving problems than on low-level coding details.
Strong Community Support: As an open-source language with a large global community, users have access to endless tutorials, forums (like Stack Overflow), and pre-built code.
Versatility: It is a general-purpose language used for everything from web apps and automation scripts to sophisticated machine learning models and scientific computing.

Top comments (0)