VND Openxmlformats-Officedocument Wordprocessingml

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Advanced python – Artificial Intelligence

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

Binary or Machine Code

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

Why machines can understand only Binary Language?


Why can’t computers understand English why only those 0s and 1s and the answers
are these 0s and 1s contribute to a concept called truth table, and 0 is represented as
false and anything non zero represents true as there are only 2 numbers 0s and 1s in
binary language so 0 represents false and 1 represents true, in short, circuit only work
on open or closed circuit.

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.

Features of Assembly Language


First step to improve programming structure and make machine language more
understandable by humans.

This is the second generation of computer language


Replacing the 0s and 1s this language used a set of symbols and letters.
Uses Assembler for converting Assembly lanuguage code to machine level code.
Example: To add or subtract it uses to add or sub respectively

High Level Language


Problems with Assembly Language: Assembly language was not as hard as Machine
Level Language but it was still hard for many of us, to understand the difference we
can see the same Hello world code in assembly language also.
Introduction to Python
Now let’s get started with Python programming, we have already studied basic
concepts of Python in Class 9, If you do recall all the concepts then you are a champ,
but if you want to recall the concepts with me, let’s do it right now.

What is Python?
Python is a High-Level Multipurpose Interpreted Programming language that is
becoming popular day by day.

Why is Python so popular?


Easy to Learn, Read and Maintain – Highly Productive
Supports both Object and Procedure Oriented Programming
100ds of Libraries and Frameworks
Flexibility of Python Language
Big data, Machine Learning and Cloud Computing
Versatility, Efficiency, Reliability, and Speed
Databases and Scalable

[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.

Advantages of using Comments?


Using comments in programs makes our code more understandable.
It makes the program more readable which helps us remember why certain blocks of
code were written.
Prevents the execution of some lines or write a quick pseudo-code for the program.
When you can’t use a function name to explain something.
Warning of consequences of the particular block of code.
Single Line Comments

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.

So, we can even write a single-line comment as:

What are Variables?


Variables in Programming act like containers that can store different types of data or
any data value in them, a variable in a python program gives data to the computer for
processing.
Features of Variables in Python

Variables play an important role while writing a code.


Variabes are the containers which stores some values
All the variables consists of some values assigned to it.
Rules for Creating Variables in Python
A variable name must start with a letter or the underscore character
A variable name cannot start with a number

[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

You can easily assign string values to variables


Create a variable and set its value to a string with using single or multiple quote as
discussed earlier
Multi-Line – Strings in Variables

These were the single line strings stored in a variable(s).


Now we will How to store multiline strings as variables.
multiline_single = '''
This is a multiline string
This is using three double quotes
we can also three single quotes
[5]
'''
Difference between List and Tuple
LIST TUPLE
List are mutable Tuples are immutable
The implication of iteration isThe implication of iteration is
time-consuming comparatively faster
The list is better for performing operations, A tuple is appropriate for assessing the
such as insertion and deletion elements
Lists consume more memory Tuple consume less memory as compared
to the list
List have several built in method Tuple does not have many built in method
Unexpected changes and errors are more Because tuple don’t change they are less
likely to occur error prone.

Python List/Array Methods

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

NumPy is a Python library.

[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

xpoints = np.array([0, 6])


ypoints = np.array([0, 250])

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.

Python “ in” Keyword and Membership Operators


The “ in” Operator

The in operator is used to determine if a specified value is a member of a sequence


(list, tuple, string, etc.). If the value is a member of the sequence, it returns True,
otherwise, it returns False.
my_list = [1, 2, 3, 4, 5]
print(3 in my_list)

The “ not in” Operator

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]

You might also like