Sie sind auf Seite 1von 31

Python Refresher course

By:A.Shobharani

Shobha
What is Scripting Language?
• A scripting language is a “wrapper” language that integrates OS functions.
• The interpreter is a layer of software logic between your code and the
computer hardware on your machine.
Wiki Says:
• The “program” has an executable form that the computer can use directly to
execute the instructions.
• The same program in its human-readable source code form, from which
executable programs are derived (e.g., compiled)
• Python is scripting language, fast and dynamic.
• Python is called ‘scripting language’ because of it’s scalable interpreter, but
actually it
is much more than that

Shobha
What is Python?
Python is a high-level programming language which is:
 Interpreted: Python is processed at runtime by the interpreter
 Interactive: You can use a Python prompt and interact with the interpreter
directly to write your programs.
 Object-Oriented: Python supports Object-Oriented technique of
programming.
 Beginner’s Language : Python is a great language for the beginner-
level programmers and supports the development of a wide range of
applications.

Shobha
Job In Big Data space

Shobha
History of Python
 Python was conceptualized by Guido Van Rossum in the
late 1980s.
 Rossum published the first version of Python code (0.9.0)
in February 1991 at the CWI (Centrum Wiskunde &
Informatica) in the Netherlands , Amsterdam.
 Python is derived from ABC programming language, which
is a general-purpose programming language that had
been developed at the CWI.
 Rossum chose the name "Python", since he was a big
fan of Monty Python's Flying Circus.
 Python is now maintained by a core development team at
the institute, although Rossum still holds a vital role in
directing its progress.

Shobha
Python Versions
Release dates for the major and minor
versions:
 Python 1.0 - January 1994
 Python 1.5 - December 31, 1997
 Python 1.6 - September 5, 2000
 Python 2.0 - October 16, 2000
 Python 2.1 - April 17, 2001
 Python 2.2 - December 21, 2001
 Python 2.3 - July 29, 2003
 Python 2.4 - November 30, 2004
 Python 2.5 - September 19, 2006
 Python 2.6 - October 1, 2008
 Python 2.7 - July 3, 2010
Shobha
Python Versions
Release dates for the major and minor
versions:
 Python 3.0 - December 3, 2008
 Python 3.1 - June 27, 2009
 Python 3.2 - February 20, 2011
 Python 3.3 - September 29, 2012
 Python 3.4 - March 16, 2014
 Python 3.5 - September 13, 2015

Shobha
Key Changes in Python 3.0
 Python 2's print statement has been replaced by the print() function.

Old: New:

 There is only one integer type left, int.


 Some methods such as map() and filter( ) return iterator objects in Python 3
instead of lists in Python 2.
 In Python 3, a TypeError is raised as warning if we try to compare unorderable
types.
 Python 3 provides Unicode (utf-8) strings while Python 2 has ASCII str( ) types
and separate unicode( ).
 A new built-in string formatting method format() replaces the %
string
formatting operator.

Shobha
Basic Syntax
 Indentation is used in Python to delimit blocks. The number of
spaces is variable, but all statements
within the same block must be
indented the same amount.
 The header line for compound statements, such as if, while, def,
and
class should be terminated with a colon ( : ) Error!

 The semicolon ( ; ) is optional at the end of statement.


 Printing to the Screen:
 Reading Keyboard Input:
 Comments
• Single line:
• Multiple lines:
 Python files have
extension .py
Shobha
Variable
• In many s the concept
languages, of variable
is connected to memory location.
• In python, a variable is seen as a tag that is tied to
some value.
• Variable names in Python can be any length.
• It can consist of uppercase and lowercase letters (A-Z,
a-z), digits (0-9), and the underscore character (_).
• A restriction is that, a variable name can contain
digits, the first character of a variable name cannot
be a digit.
Shobha
Variables
 Python is dynamically typed. You do not need
to declare variables!
 The declaration happens automatically
when you assign a value to a variable.
 Variables can change type, simply by assigning
them a new value of a different type.
 Python allows you to assign a single value to
several variables simultaneously.
 You can also assign multiple objects to
multiple
variables.

Shobha
Web Frameworks
• Django
• Flask
• Pylons
• TurboGear
s
• Zope
• Grok
Shobha
Hello World

•Open a terminal window and type “python”


•If on Windows open a Python IDE like IDLE
•At the prompt type ‘hello world!’

>>> 'hello world!'


'hello world!'

Shobha
The Python Interpreter

•Python is an interpreted >>> 3 + 7


language 10
•The interpreter provides an >>> 3 < 15
interactive environment to True
play with the language >>> 'print me'
'print me'
•Results of expressions are >>> print 'print me'
printed on the screen print me
>>>
Shobha
The print Statement

•Elements separated by
commas print with a space >>> print 'hello'
between them hello
•A comma at the end of the >>> print 'hello', 'there'
statement (print ‘hello’,) will hello there
not print a newline
character

Shobha
Documentation
The ‘#’ starts a line comment

>>> 'this will print'


'this will print'
>>> #'this will not'
>>>

Shobha
Comments in
• Python
Single Line
Comments
#To find the sum of two numbers
a = 10 # store 10 into variable a

• Comments are non-executable statements.


• Python compiler nor PVM will execute
them.

Shobha
Comments in
• Python
Single Line
Comments
#To find the sum of two numbers
a = 10 # store 10 into variable a

• Comments are non-executable statements.


• Python compiler nor PVM will execute
them.

Shobha
Comments in
• Python
When we want to mark several lines as comment, then we can write the previous
block of code inside ””” (triple double quotes) or ’’’ (triple single quotes) in the
beginning and ending of the block as.
”””
Write a program to find the total marks scored by a
student in the subjects
”””

’’’
Write a program to find the total marks scored by a
student in the subjects
’’’

Shobha
Comments in
• Python Python
supports only single line comments.
• Multiline comments are not available in Python.
• Triple double quotes or triple single quotes
are actually not multiline comments but they are regular
strings with the exception that they can span
multiple lines.
• Use of ’’’ or ””” are not recommended for comments as
they internally occupy memory.
Shobha
Datatypes in
• Python
A datatype represents the type of data
stored into a variable or memory.
• The datatypes which are already avaiable in
Python language are called Built-in
datatypes.
• The datatypes
which are created by the programmers
are called User-Defined datatypes

Shobha
Built-in
• datatypes
None Type
• Numeric
Types
• Sequences
• Sets
• Mappings

Shobha
None
• Typean object that does not
‘None’ datatype represents
contain
any value.
• In Java, it is called ‘Null’ Object’, but in Python it is
called ‘None’ object.
• In Python program, maximum of only one ‘None’
object is
provided.
• ‘None’ type is used inside a function as a default value of
the arguments.
• When calling the function, if no value is passed, then the
default value will be taken as ‘None’.
• In Boolean expressions, ‘None’
Shobhadatatype is represents ‘False’
Numeric
• int Types
• float
• comple
x

Shobha
int
• Datatype
The int datatype represents an integer number.
• An integer number is a number without
any decimal point or fraction part.
a = 10
b = -15

int datatype supports both negative and positive
integer numbers.
• It canstore very large integer
numbers conveniently.
Shobha
Float
• datatype
The float datatype represents floating point numbers.
• A floating point number is a number that contains a decimal
point.
#For example : 0.5, -3.4567, 290.08,0.001
num = 123.45

x = 22.55e3
#here the float value is 22.55 x 103

Shobha
bool
• Datatype
The bool datatype in Python represents
boolean values.
• There are only two boolean values True or
False that can be represented by this
datatype.
• Python internally represents True as 1 and
False as 0.
Shobha
Print
>>>print
Statement
“Python" Python

>>>print “Python
Programming" Python
Programming

>>> print "Hi, I am Learning Python


Programming." Hi, I am Learning Python
Programming.

Shobha
Print
>>> print 25
Statement
25

>>> print
2*2 4

>>> print 2 + 5 + 9
16

Shobha
Print
Statement
>>> print "Hello,","I","am",“Python"
Hello, I am Python

>>> print “Python","is",27,"years","old"


Python is 27 years old

>>> print 1,2,3,4,5,6,7,8,9,0


123456789 0

Shobha
Print
Statement
>>> print "Hello Python, " + "How are
you?" Hello Python, How are you?

>>> print "I am 20 Years old " + "and" + " My friend is 21 years
old.“ I am 20 Years old and My friend is 21 years old.

Shobha

Das könnte Ihnen auch gefallen