SlideShare a Scribd company logo
A hands on session on Python

SNAKES ON THE WEB:- Python
Sumit Raj
Contents
●

What is Python ???

●

Why Python ???

●

Who uses Python ???

●

Running Python

●

Syntax Walkthroughs

●

Strings and its operations

●

Loops and Decision Making

●

List, Tuple and Dictionary

●

Functions, I/O, Date & Time

●

Modules , File I/O

●

Sending a mail using Python

●

Coding Mantras
What is Python ???






General purpose, object-oriented, high level
programming language
Widely used in the industry
Used in web programming and in standalone
applications
History
●

Created by Guido von Rossum in 1990 (BDFL)

●

Named after Monty Python's Flying Circus

●

http://www.python.org/~guido/

●

Blog http://neopythonic.blogspot.com/

●

Now works for Dropbox
Why Python ???
●

Readability, maintainability, very clear readable syntax

●

Fast development and all just works the first time...

●

very high level dynamic data types

●

Automatic memory management

●

Free and open source

●

●

●

Implemented under an open source license. Freely usable and
distributable, even for commercial use.
Simplicity, Availability (cross-platform), Interactivity (interpreted
language)
Get a good salaried Job
Batteries Included
●

The Python standard library is very extensive
●

regular expressions, codecs

●

date and time, collections, theads and mutexs

●

OS and shell level functions (mv, rm, ls)

●

Support for SQLite and Berkley databases

●

zlib, gzip, bz2, tarfile, csv, xml, md5, sha

●

logging, subprocess, email, json

●

httplib, imaplib, nntplib, smtplib

●

and much, much more ...
Who uses Python ???
Hello World
In addition to being a programming language, Python is also an
interpreter. The interpreter reads other Python programs and
commands, and executes them

Lets write our first Python Program
print “Hello World!”
Python is simple

print "Hello World!"

Python

#include <iostream.h>
int main()
{
cout << "Hello World!";
}

C++

public class helloWorld
{
public static void main(String [] args)
{
System.out.println("Hello World!");
}
}

Java
Let's dive into some code
Variables and types
>>> a = 'Hello world!'
>>> print a
'Hello world!'
>>> type(a)
<type 'str'>

•
•
•
•
•

# this is an assignment statement
# expression: outputs the value in interactive mode

Variables are created when they are assigned
No declaration required
The variable name is case sensitive: ‘val’ is not the same as ‘Val’
The type of the variable is determined by Python
A variable can be reassigned to whatever, whenever

>>> n = 12
>>> print n
12
>>> type(n)
<type 'int'>
>>> n = 12.0
>>> type(n)
<type 'float'>

>>> n = 'apa'
>>> print n
'apa'
>>> type(n)
<type 'str'>
Basic Operators
Operators

Description

Example

+

Addition

a + b will give 30

-

Subtraction

a - b will give -10

*

Multiplication

a * b will give 200

/

Division

b / a will give 2

%

Modulus

b % a will give 0

**

Exponent

a**b will give 10 to the
power 20

//

Floor Division

9//2 is equal to 4 and
9.0//2.0 is equal to 4.0
Strings: format()
>>>age = 22
>>>name = 'Sumit'
>>>len(name)
>>>print “I am %s and I have owned %d cars” %(“sumit”, 3)
I am sumit I have owned 3 cars
>>> name = name + ”Raj”
>>> 3*name
>>>name[:]
Do it !




Write a Python program to assign your USN
and Name to variables and print them.
Print your name and house number using
print formatting string “I am %s, and my
house address number is %d” and a tuple
Strings...

>>> string.lower()
>>> string.upper()
>>> string[start:end:stride]
>>> S = ‘hello world’
>>> S[0] = ‘h’
>>> S[1] = ‘e’
>>> S[-1] = ‘d’
>>> S[1:3] = ‘el’
>>> S[:-2] = ‘hello wor’
>>> S[2:] = ‘llo world’
Do it...
1) Create a variable that has your first and last name
2) Print out the first letter of your first name
3) Using splicing, extract your last name from the variable and
assign it to another
4) Try to set the first letter of your name to lowercase - what
happens? Why?
5) Have Python print out the length of your name string, hint
use len()
Indentation
●

Python uses whitespace to determine blocks of code
def greet(person):
if person == “Tim”:
print (“Hello Master”)
else:
print (“Hello {name}”.format(name=person))
Control Flow
if guess == number:
#do something
elif guess < number:
#do something else

while True:
#do something
#break when done
break
else:
#do something when the loop ends

else:
#do something else
for i in range(1, 5):
print(i)
else:
print('The for loop is over')
#1,2,3,4

for i in range(1, 5,2):
print(i)
else:
print('The for loop is over')
#1,3
Data Structures
●

List
●

●

[1, 2, 4, “Hello”, False]

●

●

Mutable data type, array-like
list.sort() ,list.append() ,len(list), list[i]

Tuple
●

●

●

Immutable data type, faster than lists
(1, 2, 3, “Hello”, False)

Dictionary
●

{42: “The answer”, “key”: “value”}
Functions
def sayHello():
print('Hello World!')
●

Order is important unless using the name
def foo(name, age, address) :
pass
foo('Tim', address='Home', age=36)

●

Default arguments are supported
def greet(name='World')
Functions
def printMax(x, y):
'''Prints the maximum of two numbers.
The two values must be integers.'''
x = int(x) # convert to integers, if possible
y = int(y)
if x > y:
return x
else:
return y
printMax(3, 5)
Input & Output
#input
something = input('Enter text: ')
#output
print(something)
Date & Time
import time; # This is required to include time module.
getTheTime = time.time()
print "Number of ticks since 12:00am, January 1, 1970:",
ticks
time.ctime()
import calendar
cal = calendar.month(2008, 1)
print "Here is the calendar:"
print cal;
Modules
●

A module allows you to logically organize your Python code.

Grouping related code into a module makes the code easier
to understand and use.
●

#In calculate.py
def add( a, b ):
print "Addition ",a+b
# Import module calculate
import calculate
# Now we can call defined function of the module as:calculate.add(10, 20)
Files
myString = ”This is a test string”
f = open('test.txt', 'w') # open for 'w'riting
f.write(myString) # write text to file
f.close() # close the file
f = open('test.txt') #read mode
while True:
line = f.readline()
if len(line) == 0: # Zero length indicates EOF
break
print(line)
f.close() # close the file
Linux and Python

”Talk is cheap. Show me the code.”
Linus Torvalds
A simple Python code to send a mail
try:
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = sender # some SMTP servers will do this
automatically, not all
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.close()
except Exception, exc:
More Resources

●

●

●

http://www.python.org/doc/faq/
Google's Python Class
https://developers.google.com/edu/python/
An Introduction to Interactive Programming in Python
https://www.coursera.org/course/interactivepython

●

http://www.codecademy.com/tracks/python

●

http://codingbat.com/python

●

http://www.tutorialspoint.com/python/index.htm

●

●

How to Think Like a Computer Scientist, Learning with Python
Allen Downey, Jeffrey Elkner, Chris Meyers
Google
Coding Mantras


InterviewStreet



Hackerrank



ProjectEuler



GSoC



BangPypers



Open Source Projects
Any Questions ???
Thank You

Reach me @:

facebook.com/sumit12dec
sumit786raj@gmail.com
9590 285 524

More Related Content

What's hot

Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
QA TrainingHub
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
Niloy Saha
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
java graphics
java graphicsjava graphics
java graphics
nilaykarade1
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
Neeru Mittal
 
Java IO
Java IOJava IO
Java IO
UTSAB NEUPANE
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
Swarit Wadhe
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
Edureka!
 
Python for loop
Python for loopPython for loop
Python for loop
Aishwarya Deshmukh
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
Mayank Bhatt
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay3
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 

What's hot (20)

Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Python programming
Python  programmingPython  programming
Python programming
 
java graphics
java graphicsjava graphics
java graphics
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Java IO
Java IOJava IO
Java IO
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
 
Python for loop
Python for loopPython for loop
Python for loop
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 

Similar to Hands on Session on Python

An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
Sumit Raj
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
usvirat1805
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
deepak kumbhar
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
UdhayaKumar175069
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
ummeafruz
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
ray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
Alefya1
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
JoshCasas1
 
Python basics
Python basicsPython basics
Python basics
RANAALIMAJEEDRAJPUT
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
admin369652
 
Python intro
Python introPython intro
Python intro
Abhinav Upadhyay
 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
Introduction to Python3 Programming Language
Introduction to Python3 Programming LanguageIntroduction to Python3 Programming Language
Introduction to Python3 Programming Language
Tushar Mittal
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ahmed Salama
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
RamziFeghali
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobikrmboya
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
Daniele Pallastrelli
 

Similar to Hands on Session on Python (20)

An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Python basics
Python basicsPython basics
Python basics
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Python basics
Python basicsPython basics
Python basics
 
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
 
Python intro
Python introPython intro
Python intro
 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
 
Introduction to Python3 Programming Language
Introduction to Python3 Programming LanguageIntroduction to Python3 Programming Language
Introduction to Python3 Programming Language
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 

Hands on Session on Python

  • 1. A hands on session on Python SNAKES ON THE WEB:- Python Sumit Raj
  • 2. Contents ● What is Python ??? ● Why Python ??? ● Who uses Python ??? ● Running Python ● Syntax Walkthroughs ● Strings and its operations ● Loops and Decision Making ● List, Tuple and Dictionary ● Functions, I/O, Date & Time ● Modules , File I/O ● Sending a mail using Python ● Coding Mantras
  • 3. What is Python ???    General purpose, object-oriented, high level programming language Widely used in the industry Used in web programming and in standalone applications
  • 4. History ● Created by Guido von Rossum in 1990 (BDFL) ● Named after Monty Python's Flying Circus ● http://www.python.org/~guido/ ● Blog http://neopythonic.blogspot.com/ ● Now works for Dropbox
  • 5. Why Python ??? ● Readability, maintainability, very clear readable syntax ● Fast development and all just works the first time... ● very high level dynamic data types ● Automatic memory management ● Free and open source ● ● ● Implemented under an open source license. Freely usable and distributable, even for commercial use. Simplicity, Availability (cross-platform), Interactivity (interpreted language) Get a good salaried Job
  • 6. Batteries Included ● The Python standard library is very extensive ● regular expressions, codecs ● date and time, collections, theads and mutexs ● OS and shell level functions (mv, rm, ls) ● Support for SQLite and Berkley databases ● zlib, gzip, bz2, tarfile, csv, xml, md5, sha ● logging, subprocess, email, json ● httplib, imaplib, nntplib, smtplib ● and much, much more ...
  • 8. Hello World In addition to being a programming language, Python is also an interpreter. The interpreter reads other Python programs and commands, and executes them Lets write our first Python Program print “Hello World!”
  • 9. Python is simple print "Hello World!" Python #include <iostream.h> int main() { cout << "Hello World!"; } C++ public class helloWorld { public static void main(String [] args) { System.out.println("Hello World!"); } } Java
  • 10. Let's dive into some code Variables and types >>> a = 'Hello world!' >>> print a 'Hello world!' >>> type(a) <type 'str'> • • • • • # this is an assignment statement # expression: outputs the value in interactive mode Variables are created when they are assigned No declaration required The variable name is case sensitive: ‘val’ is not the same as ‘Val’ The type of the variable is determined by Python A variable can be reassigned to whatever, whenever >>> n = 12 >>> print n 12 >>> type(n) <type 'int'> >>> n = 12.0 >>> type(n) <type 'float'> >>> n = 'apa' >>> print n 'apa' >>> type(n) <type 'str'>
  • 11. Basic Operators Operators Description Example + Addition a + b will give 30 - Subtraction a - b will give -10 * Multiplication a * b will give 200 / Division b / a will give 2 % Modulus b % a will give 0 ** Exponent a**b will give 10 to the power 20 // Floor Division 9//2 is equal to 4 and 9.0//2.0 is equal to 4.0
  • 12. Strings: format() >>>age = 22 >>>name = 'Sumit' >>>len(name) >>>print “I am %s and I have owned %d cars” %(“sumit”, 3) I am sumit I have owned 3 cars >>> name = name + ”Raj” >>> 3*name >>>name[:]
  • 13. Do it !   Write a Python program to assign your USN and Name to variables and print them. Print your name and house number using print formatting string “I am %s, and my house address number is %d” and a tuple
  • 14. Strings... >>> string.lower() >>> string.upper() >>> string[start:end:stride] >>> S = ‘hello world’ >>> S[0] = ‘h’ >>> S[1] = ‘e’ >>> S[-1] = ‘d’ >>> S[1:3] = ‘el’ >>> S[:-2] = ‘hello wor’ >>> S[2:] = ‘llo world’
  • 15. Do it... 1) Create a variable that has your first and last name 2) Print out the first letter of your first name 3) Using splicing, extract your last name from the variable and assign it to another 4) Try to set the first letter of your name to lowercase - what happens? Why? 5) Have Python print out the length of your name string, hint use len()
  • 16. Indentation ● Python uses whitespace to determine blocks of code def greet(person): if person == “Tim”: print (“Hello Master”) else: print (“Hello {name}”.format(name=person))
  • 17. Control Flow if guess == number: #do something elif guess < number: #do something else while True: #do something #break when done break else: #do something when the loop ends else: #do something else for i in range(1, 5): print(i) else: print('The for loop is over') #1,2,3,4 for i in range(1, 5,2): print(i) else: print('The for loop is over') #1,3
  • 18. Data Structures ● List ● ● [1, 2, 4, “Hello”, False] ● ● Mutable data type, array-like list.sort() ,list.append() ,len(list), list[i] Tuple ● ● ● Immutable data type, faster than lists (1, 2, 3, “Hello”, False) Dictionary ● {42: “The answer”, “key”: “value”}
  • 19. Functions def sayHello(): print('Hello World!') ● Order is important unless using the name def foo(name, age, address) : pass foo('Tim', address='Home', age=36) ● Default arguments are supported def greet(name='World')
  • 20. Functions def printMax(x, y): '''Prints the maximum of two numbers. The two values must be integers.''' x = int(x) # convert to integers, if possible y = int(y) if x > y: return x else: return y printMax(3, 5)
  • 21. Input & Output #input something = input('Enter text: ') #output print(something)
  • 22. Date & Time import time; # This is required to include time module. getTheTime = time.time() print "Number of ticks since 12:00am, January 1, 1970:", ticks time.ctime() import calendar cal = calendar.month(2008, 1) print "Here is the calendar:" print cal;
  • 23. Modules ● A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand and use. ● #In calculate.py def add( a, b ): print "Addition ",a+b # Import module calculate import calculate # Now we can call defined function of the module as:calculate.add(10, 20)
  • 24. Files myString = ”This is a test string” f = open('test.txt', 'w') # open for 'w'riting f.write(myString) # write text to file f.close() # close the file f = open('test.txt') #read mode while True: line = f.readline() if len(line) == 0: # Zero length indicates EOF break print(line) f.close() # close the file
  • 25. Linux and Python ”Talk is cheap. Show me the code.” Linus Torvalds
  • 26. A simple Python code to send a mail try: msg = MIMEText(content, text_subtype) msg['Subject']= subject msg['From'] = sender # some SMTP servers will do this automatically, not all conn = SMTP(SMTPserver) conn.set_debuglevel(False) conn.login(USERNAME, PASSWORD) try: conn.sendmail(sender, destination, msg.as_string()) finally: conn.close() except Exception, exc:
  • 27. More Resources ● ● ● http://www.python.org/doc/faq/ Google's Python Class https://developers.google.com/edu/python/ An Introduction to Interactive Programming in Python https://www.coursera.org/course/interactivepython ● http://www.codecademy.com/tracks/python ● http://codingbat.com/python ● http://www.tutorialspoint.com/python/index.htm ● ● How to Think Like a Computer Scientist, Learning with Python Allen Downey, Jeffrey Elkner, Chris Meyers Google
  • 30. Thank You Reach me @: facebook.com/sumit12dec sumit786raj@gmail.com 9590 285 524

Editor's Notes

  1. - needs Software Freedom Day@Alexandria University
  2. Write most useful links for beginners starting
  3. Write something more interactive