VND Openxmlformats-Officedocument Wordprocessingml
VND Openxmlformats-Officedocument Wordprocessingml
VND Openxmlformats-Officedocument Wordprocessingml
What is Programming?
So before learning what is programming, I want to ask you one simple question, why
do you use a computer or a phone, in my case I use it for google search, Meetings, a
calculator, and many more things.
So have you ever thought that how that device understands, what you want the device
to do when you click the calculator app button? This is done via programming.
Programming Languages
We know that Computers do not understand the language which we speak, like
English. Computers understand Only understand Machine language, also known
as Binary Language, technically speaking this is the only language which computers
understand… for example
Assembly Language
The Problem: We need to program the machine but it’s not easy to learn the Binary
Code or Machine language
[1]
The Solution: Due to this Assembly language was Introduced as a first step to improve
programming structure and make machine language more understandable by humans.
What is Python?
Python is a High-Level Multipurpose Interpreted Programming language that is
becoming popular day by day.
[2]
Applications of Python
[3]
What are Comments?
Comments are the piece of code that is generally ignored by the Interpreter, it helps
the programmer to keep track of the code, organize it properly, and Maintain the code
collectively in a team. It’s helpful and considered as a good practice to comment on
your code because.
In python single comments are denoted by “#”, like the example given below. The
interpreter ignores all the text after #
Multi-line Commnets
Python doesn’t offer a separate way to write multiline comments. However, there are
other ways to get around this issue. We can use # at the beginning of each line of
comment on multiple lines.
String Literals for Multi-line Comments
Even though there is no unique way to write multiline comments in Python, we know
that the Python interpreter ignores the string literals that are not assigned to a variable.
[4]
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9,
and _ )
Variable names are case-sensitive (age, Age and AGE are three different variables)
What is a Datatype ?
In previous lessons, we stored data in variables. There, some text was in quotes and
some were not in quotes. As computer don’t know how to put something under a type
of data.
For example, if you write text and number then You should tell the computer which one
is text and which integer
Strings in Python
Strings Literals
To make a string in python you need to include the text between quotes
You can Use either single quotes or double quotes. Like of the example given below
Single Line – Strings in Variables
Python has a set of built-in methods that you can use on lists/arrays.
Method Description
Append() Adds an element at the end of the list
Clear() Removes all the elements from the list
Copy() Returns a copy of the list
Count() Returns the number of element with the specified value
Extend() Add the elements of a list to the end of the current list
Index() Returns the index of the first element with the specified value
Insert() Adds an element at the specified position
Pop() Removes the element at the specified position
Remove() Removes the first item with the specified value
Reverse() Reverse the order of the list
Sort() Sorts the list
NumPy
[6]
NumPy is used for working with arrays. It also has functions for working in domain of
linear algebra, fourier transform, and matrices.
NumPy is short for "Numerical Python".
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))
[7]
What is Matplotlib?
Matplotlib is a low level graph plotting library in python that serves as a visualization
utility.
Matplotlib was created by John D. Hunter.
Matplotlib is open source and we can use it freely.
Matplotlib is mostly written in python, a few segments are written in C, Objective-C and
Javascript for Platform compatibility.
import matplotlib.pyplot as plt
import numpy as np
plt.plot(xpoints, ypoints)
plt.show()
What is the main difference between for and while loop in Python?
A for loop in Python repeats executing a code block from a sequence
till certain number of times.
Whereas a while loop in Python repeats execution of a code block till
the condition is true which is not certain.
The not in operator works similarly to the in operator, but returns True when the
specified value is not a member of the sequence and False otherwise.
my_list = [1, 2, 3, 4, 5]
places = ['london', 'istanbul', 'tokyo' ]
[8]
print(4 not in my_list)
print('London' not in places)
[9]