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

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/341712991

Python in Marathi

Presentation · February 2017


DOI: 10.13140/RG.2.2.11577.80485

CITATIONS READS

0 580

1 author:

Mayur Patil
Vishwakarma University
14 PUBLICATIONS   5 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Intrusion Detection by Forensic Method in Private Cloud using Eucalyptus View project

All content following this page was uploaded by Mayur Patil on 28 May 2020.

The user has requested enhancement of the downloaded file.


BASICS OF PYTHON

Mr. Mayur S Patil,


Pune, India.
BASICS OF PYTHON

Mr. Mayur S Patil,


Pune, India.
Contents:
• Rise of Python
• Zen of Python
• Installation modes
• Jargons of Python
• Kuizziz
• Structure of Program
• Data Structures
• Operators & Expressions
• Control Flow
• Functions
• Modules
• Object Oriented Programming
• Standard Library
• Revisited Zen of Python
• Some Jokes
• Q&A
Rise of Python:
- Guido Van Rossum
- want to draw features from ABC, modula-3, C
- nowhere to go for Chrismas
- Applicable to Unix hackers
- Monty Python Flying circus

- Founded in 1989 and Published in 1991.

- Py Software Activity 300 Individuals and 30Corpo funded GVR.


- What if he is dead? (Ref: Sams Python in 24 Hours, 1st Edition)
- Founded Python Consortium
- "goto" as sphagetti code
- OOD vs OOP
- Extensible
- Embedded
ZEN OF PYTHON BY TIM PETERS
• Beautiful is better than ugly.
• Explicit is better than implicit.

• Simple is better than complex.


• Complex is better than complicated.

• Flat is better than nested.


• Sparse is better than dense.

• Readability counts.

• Special cases aren't special enough to break the rules.


• Although practicality beats purity.
• Errors should never pass silently.

• Unless explicitly silenced.

• In the face of ambiguity, refuse the temptation to guess.

• There should be one-- and preferably only one --obvious way to do it.

• Although that way may not be obvious at first unless you're Dutch.

• Now is better than never.

• Although never is often better than *right* now.

• If the implementation is hard to explain, it's a bad idea.

• If the implementation is easy to explain, it may be a good idea.

• Namespaces are one honking great idea -- let's do more of those!


Jargons of Python:
• PEP 1, 8, 3099

• Batteries Included
• Regular expressions, documentation generation, unit testing, threading, databases, web
browsers, CGI, FTP, email, XML, XML-RPC, HTML, WAV files, cryptography, GUI (graphical
user interfaces),

• Vast set of Libraries (External)

• One liners

• Portable Python Installer

• 2to3

• virtualenv
IDE and EDITORS
 Editors
 Notepad++
 Sublime Text
 IDLE Command and Code Editor

 IDE
 VSCode
 Atom
 Pyzo
 Jupyter Notebook
Installation modes:
• Package Installer:

• Pip
• python get-pip.py
• python3 -m pip install boto3
• pip install Django==1.10.5
• pip uninstall Django

• Pip installer offline files:

• whl (wheels)
• For replace eggs, PEP 376 aims at DB of installed python distributions dist_info & PEP 426
metadata for Python Software packages.
• Older Installation Methods
• egg
• Similar like .jar in java, it consists of code, resources, metadata.
• Poor scheme due to traces remained on systems.

• Setuptools
• easy_setup.py
• Source Compilation
• .tar.gz or .tgz or .xz
• Bleeding method: make or break
Structure of Program
 Comments
• #
• “”” “””
 Literal Constants

 Numbers

 Strings

• Single Quotes
• Double Quotes
• Triple Quotes
Data Structures:
• Lists
ram = "warrior"
L = [1, "Ram", 't', 2**3, ram]
print (L)
ram= "samarth"
print (L)
L.append('S') #to append items in List
print (L)
L.pop(2) #to remove elements from List
print (L)
print (L[1])

• When:
List keeps order
Data Structures:
• Tuples
samp = "this is sample"
tup = ( 1, "Shiv", 'S', 2**3, samp ) print (tup)
samp = "this is not" print (tup)
print (tup[1])

• When:
Tuples are fixed size in nature
Data Structures:
• Actual Difference:

• Lists

>>> animals = ['cat', 'dog']

>>> animals ['cat', 'dog']

>>> animals.append('mat')

>>> animals ['cat', 'dog', 'mat']

>>> animals[2] = 'bat'

>>> animals ['cat', 'dog', 'bat']


# runtime difference between tuple and lists

# python3 -mtimeit -s 'x,y,z=1,2,3' '[x,y,z]'


# python3 -mtimeit '[1,2,3]'

# python3 -mtimeit -s 'x,y,z=1,2,3' '(x,y,z)'


# python3 -mtimeit '(1,2,3)'
 Tuples
>>> point = (3,7)
>>> point (3, 7)
>>> point[1]
7
>>> point[1] = 4
Traceback (most recent call last): File "",
line 1, in
TypeError: 'tuple' object does not support item assignment

Python tuples have a surprising trait: they are immutable, but their values may
change. This may happen when a tuple holds a reference to any mutable
object, such as a list.
 Dictionary

d['Entrance Door']=123
d['Rear Door']=456

print (d)
print (d.keys())
print (d.values())
Operators and Expressions:
• Plus
• Minus
• Multiply
• Power
• Divide (/)
• Divide and Floor (//)
• Less than <
• Greater than >
• Less equal <=
• Greater equal >=
• == COMPARISON OPERATOR
• = ASSIGNMENT OPERATOR
Control Flow:
• If – else

• For

•Ternary Operations #ternary operator


operations a,b = 10,20
 #[on_true] if [condition] else [on_false] min = a if
a < b else b
 print (min)
Functions:
def ram_func(i):
if i % 2 == 0:
print("Value is even")
elif i % 2 != 0:
print("Value is not even")
else:
print("I don't know")

ram_func(2)

• Editor
Module:

import X: this imports everything as X.var1,X.var2,etc

from X import * : this imports everthing as var1,var2 etc

,i.e it floods the local namespace


Standard Library:
•Keep under your pillow

•Identify type of Image: imghdr


>>> import imghdr

>>> imghdr.what("ram.jpeg") 'jpeg'

# change extension
>>> imghdr.what("index.gif") 'jpeg‘

# save as .gif format


>>> imghdr.what("index-copy.gif") 'gif'
Revisited
Zen of
Python
Questions
& Answers
One Liners

To start your simple web server


• python3 –m http.server <port>

Swapping
• a, b = b, a

Python Youtube Downloader


• pip install youtube-dl
• youtube-dl https://www.youtube.com/watch?v=07xzzLB6Als

Lie Detection
• ‘ram’ in ‘ramayan’
• ‘kans’ in ‘ramayan’
Install Python on Linux
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz tar
xfvJ Python-3.5.1.tar.xz -C /opt/
cd Python-3.5.1
./configure --prefix=/opt/python3.5 make
# To make idle3.5, you need tk's development to produce tkinter sudo
apt-get install tk8.6-dev
sudo make install

•Your python 3.5 interpreter will be located in /opt/python3.5/bin/python3.5. Your Integrated


Development Environment is also found in /opt/python3.5/bin/idle3.5.
• To facilitate use you can symlink these files to a location on your $PATH like so: sudo
ln -s /opt/python3.5/bin/python3.5 /usr/local/bin/py3.5
sudo ln -s /opt/python3.5/bin/idle3.5 /usr/local/bin/idle3.5

View publication stats

You might also like