2. Agenda
• What is Python?
• History of Python
• Frameworks for Python
• Flavors of Python
• Why Python
• Data Types and Variables
• String
• Tuple
• Lists
3. What is Python
An interpreted, high-level programming language for general-purpose
programming
• Platform independent
• Dynamic typing
• Automatic memory management
• Adding or changing functions at runtime
• may use elements of natural language
• Strong abstraction
• Closer to end-user
6. Flavours of Python
Flavors of Python refers to the different types of Python compilers. These flavors
are useful to integrate various programming language into Python.
• CPython: Python -> C language
• Jython: Python -> Java language
• IronPython: Python -> C# (.NET framework)
• PyPy: Python -> Python
• RubyPython: Python -> Ruby
7. Data Type
It is a characteristics that tells the Compiler how a programmer intends
to use the data
Booleans are either True or False.
Numbers can be integers, floats, fractions, or complex numbers.
Strings are sequence of Unicode characters.
Bytes and byte arrays, e.g. JPEG image file .
Lists are ordered sequence.
Tuples are ordered, immutable sequence of values.
Sets are unordered bags of values.
8. Variable
Ex: Counter = 100 # An Integer
point name = “John” # A String
Variables are reserved memory locations to store values.
String
It is a collection of letters, or sequence of characters.
String operations:
• “hello”+ “world” “helloworld” #concatenation
• “hello”*3 “hellohellohello” #repetition
• “hello”[0] “h” #indexing
• “hello”[-1] “o” # from end
9. Operators
• Add two operands or unary plus +
• Subtract or unary minus -
• Multiply two operands *
• Division operator /
• Modulus - remainder of the division %
• Floor division- division that results into
whole number
• Exponent **
//
10. Tuple
s
Tuples are used to store multiple items in a single variable. A tuples is a
collection of immutable Python objects
Tuple Functions:
• Compares elements of both tuples cmp(tuple1, tuple2)
2. Gives the totoal length of the tuple len(tuple)
3. Returns item from the tuple with max value max(tuple)
4. Returns item from the tuple with min value min(tuple)
5. Converts a list into tuple tuple(seq)
11. Lists
Lists are one of 4 built in data type in Python used to collection of
data.
List item are ordered, changeable, and allow duplicate values.
Built-in List Function and Methods:
4. Returns the lowest index in list that obj appears list.index(obj)
1. Compares elements of bothe lists. cmp(list1, list2)
2. Gives the total length of the list. len(list)
5. Appends objects obj to list list.append(obj)
3. Returns item from the list with max value max(list)
6. Sorts objects of list, use compare function of given list.sort(func)
12. Why Python?
• Python works on different platforms ( Windows,Mac, Linux, Raspberry
Pi etc).
• Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
Java
public class SwapNumbers {
public static void main(String[] args) {
float first = 12.0f, second = 24.5f;
System.out.println("--Before swap--");
System.out.println("First number = " +
first);
System.out.println("Second number = " +
second);
first = first - second;
second = first + second;
first = second - first;
System.out.println("--After swap--");
System.out.println("First number = " +
first);
System.out.println("Second number = " +
second);
}
}
C++
#include <iostream>
using namespace std;
int main(){
int a = 5, b = 10, temp;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
Pytho
n
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
Swapping of two numbers