Introduction
Introduction
Netflix
It is using Python for their "Recommender Systems" which
recommend the best web shows, and movies for users
by analyzing the data of customer’s/user’s watch history.
Amazon
Features of python
Some of the important features of Python are as follows:
Easy-to-learn − Python has few keywords, simple structure,
and a clearly defined syntax. Due to its simple syntax, you
can focus on the logic part rather than the syntax
implementations. This allows us to learn and maintain the
code in a better way.
Dynamically typed language- we need not declare the
data types of the variables that they are working with
right at the beginning. This promotes creative freedom to
use variables as they please and even modify their type later
on.
Versatile-It means to be able to adapt or to be used for
many different functions. There are countless domains
and scenarios where we use Python such as Artificial
Intelligence, Machine Learning, Data Analysis, Data Science
and Software Engineering.
Python Libraries
1. TensorFlow:
It is an open-source library used for high-level computations. It
is also used in machine learning and deep learning
algorithms. Researchers also use this Python library to solve
complex computations in Mathematics and Physics.
2. Matplotlib
This library is responsible for plotting numerical data. And
that’s why it is used in data analysis. It is also an open-
source library and plots high-defined figures like pie charts,
histograms, scatterplots, graphs, etc.
3. Pandas:
It is an open-source machine learning library that provides
flexible high-level data structures and a variety of analysis
tools. It eases data analysis, data manipulation, and
cleaning of data. Pandas support operations like analysis,
cleaning, Sorting, Concatenation, Conversion of data,
Visualizations, Aggregations, etc.
4. Numpy:
The name “Numpy” stands for “Numerical Python”. It is a
popular machine learning library that supports large
matrices and multi-dimensional data. It consists of in-built
mathematical functions for easy computations. Numpy is very
interactive and user friendly.
5. SciPy:
The name “SciPy” stands for “Scientific Python”. It is an
open-source library used for high-level scientific computations.
This library is built over an extension of Numpy. It works with
Numpy to handle complex computations. While Numpy
allows sorting and indexing of array data, the numerical data
code is stored in SciPy. It is also widely used by application
developers and engineers.
6. Scrapy:
It is an open-source library that is used for extracting data
from websites. It provides very fast web crawling and high-
level screen scraping. It can also be used for data mining
and automated testing of data.
7. Scikit-learn:
It is a famous Python library to work with complex data. Scikit-
learn is an open-source library that supports machine
learning. It supports variously supervised and
unsupervised algorithms like linear regression,
classification, clustering, etc. This library works in
association with Numpy and SciPy.
8. PyGame:
This library provides an easy interface to the Standard
Directmedia Library (SDL) platform-independent graphics,
audio, and input libraries. It is used for developing video
games using computer graphics and audio libraries along with
Python programming language. Pygame was officially written
by Pete Shinners.
9. PyTorch:
10. PyBrain:
The name “PyBrain” stands for Python Based Reinforcement
Learning, Artificial Intelligence, and Neural Networks library. It
is an open-source library built for beginners in the field of
Machine Learning. It provides fast and easy-to-use
algorithms for machine learning tasks. It is so flexible and
easily understandable and that’s why is really helpful for
developers that are new in research fields.
11. Keras
Keras is a Python-based open-source neural network library
that lets us experiment with deep neural networks
quickly. With deep learning becoming more common, Keras
emerges as a great option because, according to the
creators, it is an API (Application Programming Interface)
designed for humans, not machines. Keras has a higher
adoption rate in the industry and research community than
TensorFlow or Theano. It is recommended that you install
the TensorFlow backend engine before installing
Keras. Keras’ modular design makes it very expressive,
adaptable, and suited really well to cutting edge research.
Data is the new oil and data is everywhere. With the passing of
every second of every day, more and more data is being
generated. Thus, there is a need to manage, analyze and
interpret this humongous data. That’s where Data Science comes
into the picture.
Technology has come a long way and now in our current times,
we are successfully able to make machines learn. That’s Machine
Learning in a nutshell for you! So it is advisable to learn more
about Machine Learning along with the answer to “What is Python
Programming?”
We use Python for building algorithms and models using Statistics
to allow computers to perform actions.
Python in AI
Flask
Django
Many big websites like Instagram, Netflix, and Spotify use Python
to develop their product.
We can use it to create games like Flappy Bird, Tic Tac Toe,
Minesweeper, etc.
Not only 2D games, we can also make 3D games. For this, PySoy
can be used.
Tkinter, PyQt, and Kivy are some of the most famous libraries for
this purpose.
The most popular tools and libraries for this purpose are SCons,
Buildbot, Trac, etc.
Python can handle these things easily with its useful features like
performance, flexibility, cross-platform support, and scalability.
Some packages that can be used for this purpose are wave,
audioloop, gstreamer, pyglet
BeautifySoup
Scrapy
Requests
Selenium
Versions
Python 2 Vs. Python 3
The two versions of Python- Python 2 and Python 3 are the most
widely used Python versions and there are many differences
between these versions which are as follows:
Python 2 Python 3
The release year of Python 2 is 2000 The release year of Python 3 is 2008
In the setup window, you need to check the Add Python 3.8 to
PATH and click the Install Now to begin the installation.
It’ll take few minutes to complete the setup.
Once the setup completes, you’ll see the following window:
To verify the installation, you open the Run window and type cmd
and press Enter:
If you see the following output from the Command Prompt after
typing the python command:
It’s likely that you didn’t check the Add Python 3.8 to
PATH checkbox when you install Python.
Or by writing the content in the file and then using the .py file
extension, and running it in the Command Line:
Example:
print("Hello world");
c:\users\.....>python myfirstfile.py
Comments
Example 1:
print("Hello world");
Output:
Hello world
Continuation of statements
Example:
Output:
In this print statement we will print a very long statement with
help of slash which allow us to write content in continuation to
previous content.
Identifiers
Keywords
To find the current keyword list, you use the following code:
Example:
import keyword
print(keyword.kwlist)
Output:
String literals
Python uses single quotes ('), double quotes ("), triple single
quotes (''') and triple-double quotes (""") to denote a string literal.
The string literal need to be enclose with the same type of quotes.
For example, if you use a single quote to start a string literal, you
need to use the same single quote to end it.
Example:
s = 'This is a string'
print(s)
print(s)
print(s)
Variable
Example:
str="Hello"
print(str)
a=25
print(a)
b=14.7
print(b)
Output:
The following are the variable rules that you should keep in mind:
Variable names can contain only letters, numbers, and
underscores (_).
Variable can start with a letter or an underscore (_),
not with a number.
Variable names cannot contain spaces. To separate words
in variables, you use underscores, Eg. stud_age (for student
age).
Variable names cannot the same as keywords and built-
in functions in Python.
Multiple Assignment
Python allows you to assign a single value to several
variables simultaneously.
Example:
a=b=c=1
print(a,b,c)
Output:
Here, an integer object is created with the value 1, and all three
variables are assigned to the same memory location.
Note:We can also assign multiple objects to multiple variables.
Example:
a,b,c = 1,2,"john"
print(a,b,c)
Output:
a,b,c = 1,2,3,"abc"
print(a,b,c)
Output:
Error
Data types
The data stored in memory can be of many types. For example, a
person's age is stored as a numeric value and his or her address
is stored as alphanumeric characters. Python has various
standard data types that are used to define the operations
possible on them and the storage method for each of them.
Python has five standard data types −
Numbers
String
List
Tuple
Dictionary
The two basic categories of data types are:
Mutable
Mutable objects in Python enable the programmers to have objects that can
change their values. They generally are utilized to store a collection of data.
It can be regarded as something that has mutated, and the internal state
applicable within an object has changed.
While doing any changes to the mutable objects the memory at which those
objects are stored remains the same. This is explained in different
sections Mutable Objects read along to know more.
print(color)
Output:
color[0] = "Black"
color[-1] = "White"
print(color)
Output:
Immutable
Python is used in numbers, tuples, strings, frozen sets, and user-defined classes
with some exceptions. They cannot change, and their values and it remains
permanent once they are initialized and hence called immutable.
While doing any changes to the immutable objects, the memory at which
these objects were stored during initialization, gets updated. This is
explained in different sections Immutable Objects read along to know more.
Example:
Example:
greeting[0] = 'Hello'
print(greeting)
Output:
Error
Conclusion
1. Mutable and immutable objects are handled differently in python. Immutable
objects are quicker to access and are expensive to change because it involves the
creation of a copy.
Whereas mutable objects are easy to change.
2. Use of mutable objects is recommended when there is a need to change the size or
content of the object.
3. Exception : However, there is an exception in immutability as well. We know that
tuple in python is immutable. But the tuple consists of a sequence of names with
unchangeable bindings to objects.
Consider a tuple
tup = ([3, 4, 5], 'myname')
The tuple consists of a string and a list. Strings are immutable so we can’t change
its value. But the contents of the list can change. The tuple itself isn’t mutable
but contain items that are mutable.
As a rule of thumb, Generally Primitive-like types are probably immutable and
Customized Container-like types are mostly mutable.
Example:
x=5
print(type(x))
Output:
<class 'int'>
Python Numbers
int
float
complex
Example
To verify the type of any object in Python, use the type() function:
x = 1 # int
y = 2.8 # float
z = 1j # complex
print(type(x))
print(type(y))
print(type(z))
Output:
<class 'int'>
<class 'float'>
<class 'complex'>
Int
Integers:
x=1
y = 35656222554887711
z = -3255522
print(type(x))
print(type(y))
print(type(z))
Try it Yourself »
Float
Example
Floats:
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))
Try it Yourself »
Example
Floats:
x = 35e3
y = 12E4
z = -87.7e100
print(type(x))
print(type(y))
print(type(z))
Try it Yourself »
ADVERTISEMENT
Complex
Example
Complex:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
Try it Yourself »
Type Conversion
You can convert from one type to another with the int(), float(),
and complex() methods:
Example
x = 1 # int
y = 2.8 # float
z = 1j # complex
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
Try it Yourself »
Random Number
import random
print(random.randrange(1, 10))
Try it Yourself »
Python Casting
❮ PreviousNext ❯
Example
Integers:
x = int(1) # x will be 1
y = int(2.8) # y will be 2
z = int("3") # z will be 3
Try it Yourself »
Example
Floats:
Try it Yourself »
Example
Strings:
Boolean Values
You can evaluate any expression in Python, and get one of two
answers, True or False.
Example
print(10 > 9)
print(10 == 9)
print(10 < 9)
Output:
True
False
False
\’ Single quote
\” Double quote
\\ backslash
\n New line
\r Carriage Return
\t Horizontal tab
\b Backspace
\f form feed
Escape
Character Meaning
\v vertical tab
\0 Null character
\’ Single quote
\\ Backslash
\n Newline
\r Carriage Return
\t Horizontal Tab
\b Backspace
\f Formfeed
\v Vertical Tab
\0 Null Character
For Example,
We want to print who's this.
print('Who's this?')
How to overcome?
print('Who\'s this?')
Output:
Who's this?
We can use “\n” here, which tells the interpreter to print some
characters in the new line separately.
Example:
print('Interview\nBit')
Output:
Interview
Bit
So we can say that we will get the new line when we type \n in
the string before any word or character.
Example:
print('Interview\\Bit')
Output:
Interview\Bit
Python escape sequence for Space
Example:
print('Interview\tBit')
Output:
Interview Bit
From the above screenshot, you can see that if we want a tab
space between two words, then we can use this ‘\t’ escape
sequence to print the spaces.
Example:
print('Interview \bBit')
Output:
InterviewBit
Python escape sequence for Hexa value
Example:
print("\x48\x45\x4C\x4C\x4F\x20\x57\x4F\x52\x4C\x44")
Output:
Hello World
As you can see in the above example, the characters are printed
according to their respective Hexa values, followed by the ‘\x’.
Example:
print("\110\105\114\114\117\040\127\117\122\114\104")
Output:
Hello World
As you can see in the above example, the characters are printed
according to their respective octal values, followed by the ‘\’.
Example:
s = ['Hello','\x50','to','\x44','World']
print(s)
Output:
Example:
print(r"Hello\nWorld")
Output:
Hello\nWorld
Example:
Output:
Example:
Output:
Interview Bit
Scaler\cAcademy
Methods of Prevention
Method 1
print("Interview \t Bit")
Output:
Interview Bit
Interview \t Bit
In the first case, "\t" was considered a tab space, but in the
second one, "\t" was printed as a normal literal.
Method 2
Example:
print("C:\Interview Bit\nScaler\aAcademy")
print(r"C:\Users\Dell\OneDrive\Desktop")
Output:
C:\Interview Bit
ScalerAcademy
C:\Users\Dell\OneDrive\Desktop