This is a presentation which is an introduction to python language.
The presentation is contributed by me for educational purpose and this presentation is
Only introduction.
The Basic python data types and how to use python for Data Science,
2. Below are some facts about Python.
> Python is a widely used general-purpose, high
level programming language.
> Python allows programming in Object Oriented
and Procedural paradigms.
> Python programs generally are smaller than other
programming languages like Java.
> Programmers have to type relatively less and
identation requirement of the language, makes them
readable all the time.
3. The biggest strength of the Python is large
libarary which can be used for the following
• Machine Learning
• GUI Applications
• Web frameworks like Django (used by YouTube)
• Multimedia
• Image processing
• Test frameworks
• Web scraping
• Scientific computing
• Text processing and many more..
4. Python Language Introduction
• Python is a widely used general-purpose, high level
programming language. It was initially designed by Guido
van Rossum in 1991 and developed by Python Software
Foundation. It was mainly developed for emphasis on code
readability, and its syntax allows programmers to express
concepts in fewer lines of code.
5. There are two major Python versions- Python 2
and Python 3. Both are quite different.
• 1) Finding an Interpreter:
• Before we start Python programming, we need to have an interpreter
to interpret and run our programs. There are certain online
interpreters like http://ideone.com/ or http://codepad.org/ that can
be used to start Python without installing an interpreter
• Windows: There are many interpreters available freely to run Python
scripts like IDLE ( Integrated Development Environment ) which is
installed when you install the python software
from http://python.org/
• Linux: For Linux, Python comes bundled with the linux.
6. Writing first program:
• print(“Hello world my name is piyush rai”)
• We can comment python using #
7. DATA STRUCTURE AND PYTHON
• In other programming languages like C, C++ and Java,
you will need to declare the type of variables but in
Python you don’t need to do that.
• Just type in the variable and when values will be
given to it, then it will automatically know whether
the value given would be a int, float or char or even a
String.
8. LIST
• Is the most basic Data Structure in python. List is
mutable data structure i.e items can be added to list
later after the list creation.
• Its like you are going to shop at local market and
made a list of some items and later on you can add
more and more items to the list.
9. Input and Output
•Now, we will learn how to take input from
the user and hence manipulate it or simply
display it.
•input() function is used to take input from
the user.
10. Selection
• Selection in Python is made using the two keywords ‘if’
• and
• ‘elif’ and
• else (elseif)
11. Functions
•You can think of functions like a bunch of
code that is intended to do a particular task
in the whole Python script.
• Python used the keyword ‘def’ to define a
function.
• Now as we know any program starts from a ‘main’
function…lets create a main function like in many other
programming languages.
12. Iteration Looping
•As the name suggests it calls repeating
things again and again. We will use the most
popular ‘for’ loop here.
13. Modules
• Python has a very rich module library that has several
functions to do many tasks. You can read more about
Python’s standard library on python.org
• ‘import’ keyword is used to import a particular
module into your python code. For instance consider
the following program.
14. Python vs Java
Python Java
Dynamically Typed1.No need to declare
anything. An assignment statement binds a
name to an object, and the object can be of
any type.2.No type casting required when
using container objects
Statically Typed 1.All variable names (along
with their types) must be explicitly declared.
Attempting to assign an object of the wrong
type to a variable name triggers a type
exception.2.Type casting is required when
using container objects.
Concise Express much in limited
words
Verbose Contains more words
Compact Less Compact
Uses Indentation for structuring code Uses braces for structuring code
15. Important differences between Python 2.x
and Python 3.x with examples
• Division operator
• print function
• Unicode
• xrange
• Error Handling
• _future_ module
16. Keywords in Python
• Python Keywords – Introduction
• This article aims at providing a detailed insight to these
keywords.
• 1. True : This keyword is used to represent a boolean
true. If a statement is true, “True” is printed.
• 2. False : This keyword is used to represent a boolean
false. If a statement is false, “False” is printed.
True and False in python are same as 1 and 0.
Example:
17. 3. None : This is a special constant used to denote a null
value or a void. Its important to remember, 0, any empty
container(e.g empty list) do not compute to None.
It is an object of its own datatype – NoneType. It is not
possible to create multiple None objects and can assign it to
variables.
4. and : This a logical operator in python. “and” Return the
first false value .if not found return last. The truth table for
“and” is depicted below.
18. 5. or : This a logical operator in python. “or” Return
the first True value.if not found return last.The truth
table for “or” is depicted below
6. not : This logical operator inverts the truth
value. The truth table for “not” is depicted
below.
19. More About input in python
• We can also type cast this input to integer, float or string by
specifying the input() function inside the type.
• Typecasting the input to Integer: There might be conditions
when you might require integer input from user/Console,
the following code takes two input(integer/float) from
console and typecasts them to integer then prints the sum.
• Typecasting the input to Float: To convert the input to float
the following code will work out.
• Typecasting the input to String: All kind of input can be
converted to string type whether they are float or integer.
We make use of keyword str for typecasting.