Introduction to modern python.
Faith K
Posted on February 14, 2022
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance.
Advantages of Python
Easy to use and learn: For beginners, Python is straightforward to use. It is a high-level programming language, and its syntax is like the English language. These reasons make the language easy to learn and adapt to. Compared to Java and C, in Python, the same task can be performed using fewer lines of code. As a result of its easy learning, the principles in Python can be executed faster compared to other languages.
Increased productivity: Python is a very productive language. The simple nature of Python helps the developers to concentrate on solving the issues in it. To understand the syntax and behavior of the programming language, the users do not have to spend hours, so more work is done.
Flexibility: This language is very flexible, and hence it allows the user to try new things. The users can develop new sorts of the application using Python programming language. The language does not restrict the user from trying something different. Other programming languages do not provide this type of flexibility and freedom, and hence Python is more preferred in these matters.
Uses and application of Python programming language.
Python can be used for:
• AI and machine learning.
• Data analytics.
• Data visualisation.
• Programming applications.
• Web development.
• Game development.
• Language development.
• Finance.
THE PYTHON ENVIRONMENT
1. Download Python
2.Select your Operating system(Windows,Linux/UNIX,MacOS,Other
3.Select the release or version, click on it to download.
4.Double click on the file to execute and install.
5.For window mark “add to system paths”
OR
If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands:
$ sudo apt-get update
$ sudo apt-get install python3.6
The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.
More : Pipenv & Virtual Environments docs!
Python fundamentals.
Functions
A program could be long and complicated but it is built of simple parts.
Variable: Helps keep track of the information we need to successfully execute a program.
my_name = 'Faith'
my_age = 32
print('My name is', my_name)
print('My age is', my_age)
String: Is a sequence of characters.
Numbers - There are three numeric types in python;
• Integer - is a whole number, positive or negative, without decimal e.g 21
• Complex - these are written with a "j" as the imaginary part e.g 67j
• Booleans - These store an output of either True or False
• Float - is a number, negative or positive containing one or more decimal points e.g 213.8
Functions: Allow us to define a task we would like the computer to carry out based on input. We define functions using def. .A function is a block of code that only runs when it's called.
Functions enable the resuse of repetitive parts of the program.
Below is a function to print a user's name.
Def say-hello():
my_name= ”Faith Kavesu”
print(‘Hello’,my_name)
Data Structures (Lists, Tuples, Dictionary & Sets)
List: Python lists are used to store data in array format. Different data types can be stored in the same list.Ordered collection of items using square bracket. Let’s try creating a list of to-do.
todo= ['read', 'cleaning', ‘colour']
todo.append('eat')
print(todo)
Tuples: It is similar to a list with major difference that it is immutable. We create using parentheses ()
todoo= ('cook','clean','code','sleep')
print(todoo)
print(todoo[0:2])
Dictionary: Involves a key associated with a value in a key-value pair. The key-value pair are in {} syntax to create a dict. Each key-value pair is separated by a comma, and within a pair the key and value are separated by a colon :
user = {
"name" : 'Faith',
"age" : 32,
"height" : "156"
}
print(user)
print(user['age'])
Set:They are used to store multiple items in a single variable. Sets contain unique items and there cannot be any duplicates or else they will be eliminated.Similar to a list except that it is unordered. It can store heterogenous data and it is mutable. Creating a set enclosed in a curly bracket {}.
set1 = {"Faith", "32", "173"}
print(my_set)
Posted on February 14, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024