Overview of Python History of Python
Overview of Python History of Python
Overview of Python History of Python
1. Overview of Python
1.1. History of Python:
Python is an easy to learn, powerful and an Opensoruce programming language. It
is a scripting language with Object oriented features. It was invented by Guido Van
Rossum from Netherland in 1989. The first version of Python was released in February
1991. Python 2.0 was released on 16 October 2000.
The current standard versions of Python are: 2.5, 2.6,2.7 and 3.0. Latest version is 3.3
released in September 29 2012.
The name Python came from the “Monty Python's Flying Circus” which impressed
Guido very well.
Disadvantages:
Slow compared to other programming languages like C,C++ or java
Threading not fully implemented.
All strings are not Unicode by default (Fixed in 3.0)
Indentation – If mix tabs and spaces.
1.3. Installing Python:
It is very simple to install python in any platform. Download Python from
http://www.python.org/ and install it at C:\Python27\ For users with 64-bit systems, the
32-bit version of all software is recommended.
Open the Command Prompt and Type into the Command Prompt window:
set path=%path%;C:\Python27\ And hit enter.
You only need to do this once and never again.
1.4. Documentation:
Following are the different resources available for Python documentation:
http://docs.python.org/2/tutorial/ - Official python tutorial
http://www.python.org/doc/ - Another official Python website.
http://www.learnpython.org/ - Where you can learn python by executing
the python online.
http://www.tutorialspoint.com/python/ - From tutorial point.
http://pythonmonk.com/
You can use IDLE as a calculator. We can single python statement from Shell. We can also create
and execute Python scripts using IDLE.
Based on the data type of a variable, the interpreter allocates memory and decides what can
be stored in the reserved memory. Therefore, by assigning different data types to variables, you
can store integers, decimals, or characters in these variables.
The operand to the left of the = operator is the name of the variable, and the operand to the right
of the = operator is the value stored in the variable. For example:
print counter
print miles
print name
Here 100, 1000.0 and "John" are the values assigned to counter, miles and name variables,
respectively. While running this program, this will produce following result:
100
1000.0
John
Multiple Assignment:
Python allows you to assign a single value to several variables simultaneously. For example:
a=b=c=1
Here, an integer object is created with the value 1, and all three variables are assigned to the
same memory location. You can also assign multiple objects to multiple variables. For example:
a, b, c = 1, 2, "john"
Here two integer objects with values 1 and 2 are assigned to variables a and b, and one string
object with the value "john" is assigned to the variable c.
Numbers
o Int
o Long
o Float
o complex
String
Bool – True or False
Other data structures like List, Tuple, Dictionary.
Python Numbers:
Number data types store numeric values. They are immutable data types, which means that
changing the value of a number data type results in a newly allocated object.
Number objects are created when you assign a value to them. For example:
var1 = 1
var2 = 10
You can also delete the reference to a number object by using the del statement. The syntax of
the del statement is:
del var1[,var2[,var3[....,varN]]]]
You can delete a single object or multiple objects by using the del statement. For example:
del var
del var_a, var_b
Python supports four different numerical types:
Examples:
Here are some examples of numbers:
int long float complex
Python allows you to use a lowercase L with long, but it is recommended that you use only an
uppercase L to avoid confusion with the number 1. Python displays long integers with an
uppercase L.
A complex number consists of an ordered pair of real floatingpoint numbers denoted by a + bj,
where a is the real part and b is the imaginary part of the complex number.
Python Strings:
Strings in Python are identified as a contiguous set of characters in between quotation marks.
Python allows for either pairs of single or double quotes. Subsets of strings can be taken using
the slice operator ( [ ] and [ : ] ) with indexes starting at 0 in the beginning of the string and
working their way from -1 at the end.
The plus ( + ) sign is the string concatenation operator, and the asterisk ( * ) is the repetition
operator. For example:
#!/usr/bin/python
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
3. Data Structures
Control Structures
a. Strings:
Strings are amongst the most popular types in Python. We can create them simply by enclosing
characters in quotes. Python treats single quotes the same as double quotes.
Creating strings is as simple as assigning a value to a variable. For example:
var1 = 'Hello World!'
var2 = "Python Programming"
Accessing Values in Strings:
Python does not support a character type; these are treated as strings of length one, thus also
considered a substring.
To access substrings, use the square brackets for slicing along with the index or indices to obtain
your substring. Following is a simple example:
#!/usr/bin/python
\b 0x08 Backspace
\cx Control-x
\C-x Control-x
\e 0x1b Escape
\f 0x0c Formfeed
\M-\C-x Meta-Control-x
\n 0x0a Newline
\s 0x20 Space
\t 0x09 Tab
\x Character x
a + b will
Concatenation - Adds values on either side of the
+ give
operator
HelloPython
a[1] will
[] Slice - Gives the character from the given index
give e
a[1:4] will
[:] Range Slice - Gives the characters from the given range
give ell
See at next
% Format - Performs String formatting
section
%c character
%o octal integer
Other supported symbols and functionality are listed in the following table:
Symbol Functionality
- left justification
Triple Quotes:
Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including
verbatim NEWLINEs, TABs, and any other special characters.
The syntax for triple quotes consists of three consecutive single or double quotes.
#!/usr/bin/python
print 'C:\\nowhere'
When the above code is executed, it produces following result:
C:\nowhere
Now let's make use of raw string. We would put expression in r'expression' as follows:
#!/usr/bin/python
print r'C:\\nowhere'
When the above code is executed, it produces following result:
C:\\nowhere
Unicode String:
Normal strings in Python are stored internally as 8-bit ASCII, while Unicode strings are stored as
16-bit Unicode. This allows for a more varied set of characters, including special characters from
most languages in the world. I'll restrict my treatment of Unicode strings to the following:
#!/usr/bin/python
capitalize()
1
Capitalizes first letter of string
center(width, fillchar)
2
Returns a space-padded string with the original string centered to a total of width columns
decode(encoding='UTF-8',errors='strict')
3 Decodes the string using the codec registered for encoding. encoding defaults to the default
string encoding.
encode(encoding='UTF-8',errors='strict')
4 Returns encoded string version of string; on error, default is to raise a ValueError unless
errors is given with 'ignore' or 'replace'.
expandtabs(tabsize=8)
6
Expands tabs in string to multiple spaces; defaults to 8 spaces per tab if tabsize not provided
find(str, beg=0 end=len(string))
7 Determine if str occurs in string, or in a substring of string if starting index beg and ending
index end are given; returns index if found and -1 otherwise
isalnum()
9 Returns true if string has at least 1 character and all characters are alphanumeric and false
otherwise
isalpha()
10 Returns true if string has at least 1 character and all characters are alphabetic and false
otherwise
isdigit()
11
Returns true if string contains only digits and false otherwise
islower()
12 Returns true if string has at least 1 cased character and all cased characters are in lowercase
and false otherwise
isnumeric()
13
Returns true if a unicode string contains only numeric characters and false otherwise
isspace()
14
Returns true if string contains only whitespace characters and false otherwise
istitle()
15
Returns true if string is properly "titlecased" and false otherwise
isupper()
16 Returns true if string has at least one cased character and all cased characters are in
uppercase and false otherwise
join(seq)
17 Merges (concatenates) the string representations of elements in sequence seq into a string,
with separator string
len(string)
18
Returns the length of the string
ljust(width[, fillchar])
19 Returns a space-padded string with the original string left-justified to a total of width
columns
lower()
20
Converts all uppercase letters in string to lowercase
lstrip()
21
Removes all leading whitespace in string
maketrans()
22
Returns a translation table to be used in translate function.
max(str)
23
Returns the max alphabetical character from the string str
min(str)
24
Returns the min alphabetical character from the string str
rfind(str, beg=0,end=len(string))
26
Same as find(), but search backwards in string
rjust(width,[, fillchar])
28 Returns a space-padded string with the original string right-justified to a total of width
columns.
rstrip()
29
Removes all trailing whitespace of string
split(str="", num=string.count(str))
30 Splits string according to delimiter str (space if not provided) and returns list of substrings;
split into at most num substrings if given
splitlines( num=string.count('\n'))
31 Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs
removed
startswith(str, beg=0,end=len(string))
32 Determines if string or a substring of string (if starting index beg and ending index end are
given) starts with substring str; Returns true if so, and false otherwise
strip([chars])
33
Performs both lstrip() and rstrip() on string
swapcase()
34
Inverts case for all letters in string
title()
35 Returns "titlecased" version of string, that is, all words begin with uppercase, and the rest
are lowercase
translate(table, deletechars="")
36 Translates string according to translation table str(256 chars), removing those in the del
string
upper()
37
Converts lowercase letters in string to uppercase
zfill (width)
38 Returns original string leftpadded with zeros to a total of width characters; intended for
numbers, zfill() retains any sign given (less one zero)
isdecimal()
39
Returns true if a unicode string contains only decimal characters and false otherwise