What is Programming and Python?
What is Programming
Welcome to my course on Python programming. If you know me, you
know that I always start a beginner Python class with a fundamental
question - "What is Programming".
Programming is a way for us to tell computers what to do. The computer
is a very dumb machine and it only does what we tell it to do. Hence we
learn to program and tell computers to do what we are very slow at -
computation. If I ask you to calculate 5+6, you will immediately say 11.
How about 23453453 X 56456?
You will start searching for a calculator or jump to a new tab to calculate
the same. This 100 days of code series will help you learn Python from
starting to the end. We will start from 0 and by the time we end this
course, I promise you will be a Job ready Python developer!
What is Python?
• Python is a dynamically typed, general-purpose
programming language that supports an object-
oriented programming approach as well as a functional
programming approach.
• Python is an interpreted (meaning, source code of a
Python program is converted into bytecode that is then
executed by the Python virtual machine) and high-level
programming language.
• It was created by Guido Van Rossum in 1989.
Features of Python
• Python is simple and easy to understand.
• It is Interpreted and platform-independent which makes
debugging very easy.
• Python is an open-source programming language.
• Python provides very big library support. Some popular
libraries include NumPy, Tensorflow, Selenium, OpenCV,
etc.
• It is possible to integrate other programming languages
within Python.
What is Python used for
• Python is used in Data Visualization to create plots and
graphical representations.
• Python helps in Data Analytics to analyze and
understand raw data for insights and trends.
• It is used in AI and Machine Learning to simulate human
behavior and to learn from past data without hard
coding.
• It is used to create web applications.
• It can be used to work with databases.
• It is used in business and accounting to perform
complex mathematical operations along with
quantitative and qualitative analysis.
In this tutorial, we will use Replit to create a Python program
Day 3 - Modules and pip in Python!
Module is like a code library which can be used to borrow code
written by somebody else in our python program. There are two
types of modules in python:
1. Built in Modules - These modules are ready to import
and use and ships with the python interpreter. there is no
need to install such modules explicitly.
2. External Modules - These modules are imported from a
third party file or can be installed using a package
manager like pip or conda. Since this code is written by
someone else, we can install different versions of a same
module with time.
The pip command
It can be used as a package manager pip to install a python
module. Lets install a module called pandas using the following
command
pip install pandas
Copy
Using a module in Python (Usage)
We use the import syntax to import a module in Python. Here is
an example code:
import pandas
# Read and work with a file named 'words.csv'
df = pandas.read_csv('words.csv')
print(df) # This will display first few rows from the words.csv file
Day 4 - Our First Program
Today we will write our first ever python program from scratch. It will
consist of a bunch of print statements. print can be used to print
something on the console in python
Quick Quiz
Write a program to print a poem in Python. Choose the poem of your
choice and publish your repl
print("---Your poem here---")
Please make sure you attempt this. Might be easy for some of you but
please finish each and every task
Day 5 - Comments, Escape sequence &
Print in Python
Welcome to Day 5 of 100DaysOfCode. Today we will talk about
Comments, Escape Sequences and little bit more about print
statement in Python. We will also throw some light on Escape
Sequences
Python Comments
A comment is a part of the coding file that the programmer does
not want to execute, rather the programmer uses it to either
explain a block of code or to avoid the execution of a specific
part of code while testing.
Single-Line Comments:
To write a comment just add a ‘#’ at the start of the line.
Example 1
#This is a 'Single-Line Comment'
print("This is a print statement.")
Copy
Output:
This is a print statement.
Copy
Example 2
print("Hello World !!!") #Printing Hello World
Copy
Output:
Hello World !!!
Copy
Example 3:
print("Python Program")
#print("Python Program")
Copy
Output:
Python Program
Copy
Multi-Line Comments:
To write multi-line comments you can use ‘#’ at each line or you
can use the multiline string.
Example 1: The use of ‘#’.
#It will execute a block of code if a specified condition is true.
#If the condition is false then it will execute another block of
code.
p = 7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
Copy
Output:
p is greater than 5.
Copy
Example 2: The use of multiline string.
"""This is an if-else statement.
It will execute a block of code if a specified condition is true.
If the condition is false then it will execute another block of
code."""
p = 7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
Copy
Output
p is greater than 5.
Copy
Escape Sequence Characters
To insert characters that cannot be directly used in a string, we
use an escape sequence character.
An escape sequence character is a backslash \ followed by the
character you want to insert.
An example of a character that cannot be directly used in a
string is a double quote inside a string that is surrounded by
double quotes:
print("This doesnt "execute")
print("This will \" execute")
Copy
More on Print statement
The syntax of a print statement looks something like this:
print(object(s), sep=separator, end=end, file=file, flush=flush)
Copy
Other Parameters of Print Statement
1. object(s): Any object, and as many as you like. Will be
converted to string before printed
2. sep='separator': Specify how to separate the objects, if
there is more than one. Default is ' '
3. end='end': Specify what to print at the end. Default is '\n'
(line feed)
4. file: An object with a write method. Default is sys.stdout
Parameters 2 to 4 are optional