+ All Categories
Home > Education > Python overview

Python overview

Date post: 17-Aug-2015
Category:
Upload: hemant-kumar-tiwari
View: 91 times
Download: 1 times
Share this document with a friend
26
Python Overview
Transcript
Page 1: Python   overview

PythonOverview

Page 2: Python   overview

Definition

Python is a widely used general-purpose, high-level programming language that lets you work quickly and integrate systems more effectively.

Page 3: Python   overview

Philosophy

● Beautiful is better than Ugly● Explicit is better than Implicit● Simple is better than Complex● Complex is better than Complicated● Readability counts

Page 4: Python   overview

Command to check version

hemant@ubuntu:~$ pythonPython 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.>>> |

Page 5: Python   overview

Arithmetic Operators allowed

Arithmetic operators we can use:+ - * / Addition, Subtraction/Negation, Multiplication, Division

% Modulus, a.k.a. remainder

** Exponentiation

Page 6: Python   overview

“+” and “-” have equal precedence“*”, “/”, “%” and “**” have equal precedence

“*”, “/”, “%” and “**” have a higher precedence than “+” and “-”

Operators Precedence

Page 7: Python   overview

Operations Examples

Parentheses can be used to force a certain order of evaluation.(1 + 3) * 4 is 16Division results as an integer.35 / 5 is 7, 84 / 10 is 8The % operator computes the remainder from a division of integers.35 % 5 is 0, 8 % 3 is 2

Page 8: Python   overview

Print command Examples

Print : It print output to console.Syntax:print "Python"print Expressionprint 3,6,”python”total_session = 2print "You have", total_session - 1, " session left"Output : You have 1 session left

Page 9: Python   overview

Command to Input Data

>>> name1 = input("What is your name? ")What is your name? "hemant">>> print name1hemant

>>> age = input("How old are you? ")How old are you? 10>>> print "Your age is", ageYour age is 10

Page 10: Python   overview

Command to Manage “Loop’s”

Loop: Repeats a statements or set of statements as group.

Example:for name in studentslist: print name

Page 11: Python   overview

Note : We indent the statements to be repeated with tabs or spaces.Example :>>> studentlist = ["Eric", "John", "Michael"]>>> for name in studentlist:... print name

Loop’s

Page 12: Python   overview

Loop’s for a define ‘Range’

The range function specifies a range of integers:range(start, stop) - the integers between start (inclusive) and stop (exclusive)It can also accept a third value specifying the change between values.range(start, stop, step)

Page 13: Python   overview

Example:>>> for x in range(5, 0, -1):... print x

>>> for x in range(0, 5, 1):... print x

Example for ‘Range’

Page 14: Python   overview

Example for Whilewhile loop: Executes a group of statements as long as a condition is True.Syntax:while condition: statements

Example:number = 10while number < 40: print number number = number * 2

Page 15: Python   overview

Conditional Statement

if statement: Executes a group of statements in true condition.if condition: statementsif/else statement: If block execute in true condition otherwise else get executed.if condition: statementselse: statements

Page 16: Python   overview

Logical Operator

Relational Operators:== , != , < , >, <= , >=

Logical Operator and, or, not

Page 17: Python   overview

StringString: A sequence of text characters in a program. it start and end with quotation mark " or apostrophe ' characters.

Examples: "hello"

A string can represent characters by preceding them with a backslash.\t tab character\n new line character\" quotation mark character\\ backslash character

Page 18: Python   overview

String - Operatorslen(String) - Number of characters in a string (Including spaces)str.lower(String)- Lowercase version of a stringstr.upper(String) - Uppercase version of a string

Example:name = "Python Django Delhi"length = len(name)big_name = str.upper(name)print big_name, "has", length, "characters"

Page 19: Python   overview

Command to take Input

raw_input : Reads a string of text from user input.

Example:n1 = raw_input("Enter first number? ")n2 = raw_input("Enter second number? ")print n1 + n2

Page 20: Python   overview

String-Indexes /Text ProcessingCharacters in a string can be access through indexes starting at 0. Accessing an individual character of a string:

Example 1:name = "Python"print name, "starts with", name[0]Output: Python starts with P

Example 2:for c in "Python": print c

Page 21: Python   overview

String to Numbers Conversion

ord(text) - Converts a string into a number.Example: ord("A") is 65, ord("a") is 97

chr(number) - Converts a number into a string.Example: chr(98) is "b"

Page 22: Python   overview

Command for File HandlingReading the entire contents of a file:variableName = open("filename").read()Example:>>> f1 = open("/home/django/svn_install.txt").read()>>> print f1

Line by Line>>> for line in open("/home/django/svn_install.txt").readlines():... print line... print "-----------"

Page 23: Python   overview

File Handling [Continue]Writing Data in file

>>> handle = open("/home/django/sample.txt", "w")>>> handle.write("sample data text")>>> handle.close()

Reading data from file

>>> f1 = open("/home/django/sample.txt").read()>>> print f1sample data text

Page 24: Python   overview

There are several popular implementations of the Python programming language on different back-ends.

Jython Compiles into Java byte code, which can then be executed by every Java Virtual Machine implementation. This also enables the use of Java class library functions from the Python program.

IronPython follows a similar approach in order to run Python programs on the .NET Common Language Runtime.

Cython and Pyrex compile to C.

PyPy is a Python interpreter and just-in-time compiler. PyPy focuses on speed, efficiency and compatibility with the original CPython interpreter.

Implementations

Page 25: Python   overview

https://wiki.python.org/moin/OrganizationsUsingPython

Organizations that use Python

Page 26: Python   overview

Thank You.


Recommended