Python Recap: Tata Consultancy Services
Python Recap: Tata Consultancy Services
PYTHON
RECAP
Ashwin Joy | Technical Faculty | TD Kochi
BASICS
Printing data
Numbers and strings
Variables
Getting user input
Writing comments
OPERATORS
Arithmetic + - * / %
Increment & decrement ++ --
Relational == != < > <= >=
Logical and or not
Assignment =
CONDITIONAL
STATEMENTS
if statement
else statement
elif statement
indentation in python
LOOPS
Loops allow us to execute a statement or group of statements multiple times. Thus we can
reduce the burden of repeatedly writing a piece of code many times.
while loop
for loop
FUNCTIONS
A function is a block of code which only runs when it is called. You can pass data, known as
parameters, into a function. A function can return data as a result.
in-built functions
user defined functions
STRINGS
A string is created by entering a text between two single or double-quotes.
String concatenation
String slicing
String splitting
LISTS
If we want to store a set of items in an arranged order, we can use lists in Python. We can
create a list by using square brackets with items inside. We can use commas to separate
each item.
The modules that are pre-installed with Python constitute the standard library of Python.
DICTIONARIES
Dictionaries are a special type of data structure in python. They are used to store key-value
pairs.
Examples of tuples
Mutable vs immutable data types
SETS
Example:
print("{0}{1}{0}".format("abra","cad"))
EXCEPTION HANDLING
An exception is an event that occurs due to incorrect code or input. We can handle
exceptions in Python using try-except statements.
Types of exceptions/errors.
The try-except block
The finally statement
FILE HANDLING
We can use python to read and write the contents of files.
Opening files
Reading files
Writing to files
REGEX
A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern.
RegEx can be used to check if a string contains the specified search pattern.
Example:
import re
txt = "The rain in Spain"
x = re.findall("ai", txt)
print(x)
OOP CONCEPTS
Object-oriented programming (OOP) is a programming paradigm based on the concept of
objects and data. We treat every entity as an object in OOP.Just like we call everything we
see in real-life as objects, we call every entity in OOP as objects.
Class
Methods
The __init__ method
INHERITANCE
The process of deriving a new class from an old class (parent class) is known as inheritance.
The old class is called the superclass and the new one is called the subclass. The subclass
can use all the stuff that is inside a superclass.
POLYMORPHISM
Polymorphism is the property by which objects belonging to different classes
are able to respond to the same message but in different ways.
Encapsulation is used to restrict access to methods and variables. The code and
data are enclosed within a single unit, just like a capsule, from being modified
by external agents.
THANK YOU
Ashwin Joy
Technical Faculty - Talent Development Kochi
Tata Consultancy Services Ltd.