Fundamentals of Python Programming
Python is a simple yet powerful programming language which focuses on code readability and crisp syntax with fewer lines of code. Facebook, YouTube, Google, NASA, Amazon are a few of the biggest companies who have been heavily adopting this language. Python has a rich library of functions which makes it a popular programming language for machine learning, natural language processing and other AI applications.
Most popular Python libraries are
- TensorFlow, Keras, Scikit: Artificial Intelligence
- NumPy, SciPy, MatPlotLib: Scientific computing
- Biopython: Computational Biology & Bioinformatics
- Astropy: Astronomy
For the purpose of this series, we will be focusing mostly on Scientific computing for Predictive analysis with the relevant libraries. Before starting this session, if you are completely new to coding then I would recommend a read through Coding for Beginners page and Object Oriented Programming.
Now to start programming in a language, we need to first setup environment and learn the building blocks of the language to start experiment and learn.
Version: Based on OS version, you will have to choose the Python version that needs to be installed on your machine. You can find more information on which version is more suitable for your OS on here.
Once you setup the environment, there are multiple open source web/standalone development environments that can be used. We will be using Jupyter in this series simply because its easy to install and easy-to-use. You can easily follow the steps to install Python and Jupyter and once you are done, we start with the building blocks.
Data Types
- Integers: Python interprets a sequence of decimal digits without any prefix to be a decimal number
- Float: The float type in Python designates a floating-point number
- Boolean: Python provides a Boolean data type & objects of Boolean type may have one of two values, True/False
- Complex numbers: Complex numbers are specified as <real part>+<imaginary part>j e.g. 3+2j
- Strings:Strings are sequences of character data that is delimited using either single or double quotes
Functions
Python 3.6 interpreter support almost sixty-eight built-in functions and you can explore Python documentation on built-in functions for more details.
How to build your own functions
1) Starting with the traditional first function of Programming in new language.
def first_function()
print("Hello World")
first_function()
Output: "Hello World"
2) Function with Arguments
def first_function(day_time, first_name)
print("Good "+day_time+", "+first_name)
first_function("morning","Joe")
print("Good "+day_time+", "+first_name)
first_function("morning","Joe")
Output: "Good morning, Joe"
3) Run-time Inputs
name=input("Tell me your name")
#the input value is stored in 'name' variable and can be printed later print(name) function
Conditional Statements & Recursion
Problems like solving Factorial need calling same function within same function for finite number of times with conditional statements. Python has a great option of introducing third condition/possibility within if/else statement as explained below.
def factorial(n):
if(n>0):
result = n*factorial(n-1)
if(n>0):
result = n*factorial(n-1)
elif(n==1):
result = 1
else:
result = 0 print(result)
We have covered the basics of Programming in Python to get started. Keep Exploring with some simple examples. Please share your comments/examples/advice so that we all can learn together.
Happy Learning!
Comments
Post a Comment