Introduction to strings in python


In Python, the strings should be created by simply enclosing the characters in quotes. Python does not support the character types. These are treated as length-one strings, and are also considered as substrings. Substrings are immutable and can’t be changed once created.

Strings are the ordered blocks of text that are enclosed in single or double quotations. Thus, whatever is written in quotes, is considered as string. Though it can be written in single or double quotations, double quotation marks allow the user to extend strings over multiple lines without backslashes, which is usually the signal of continuation of an expression, e.g., ‘abc’, “ABC”.

Concatenation and Repetition

  • Strings are concatenated with the +sign:

>>> ‘abc’+‘def’


  • Strings are repeated with the *sign:

>>> ‘abc’*3


Indexing and Slicing Operation

  • Python starts the indexing at ‘0’
  • A string s will have indexes running from 0 to len(s)-1 (where len(s) is the length of s) in integer quantities.
  • S[i] fetches the ‘i’th element in the s.

Built-in String Methods

Following are the built-in String Methods that can be used in Python:

  • capitalize() – This method is used to capitalize the first letter of string.
  • count(str, beg= 0, end=len(string)) – Used to count how many times  the str occurs in string or in a substring of string, if beginning index ‘beg’ and ending index ‘end’ are given.
  • encode(encoding=‘UTF-8’,errors=‘strict’) – This method is used to return the encoded string version of string; on error, default raises a ValueError, unless the error is given with ‘ignore’ or ‘replace’.
  • decode (encoding=‘UTF-8’, errors=‘strict’) – This method is used to decode the string using the codec registered for Encoding. Encoding defaults to the default string function.
  • index(str, beg=0, end=len(string))- Same as find(), but it raises an exception if str is not found.
  • max(str)- Used to return the max alphabetical character from the string str.
  • min(str)- This is used to return the min alphabetical character from the string str.
  • replace(old, new [, max])- This method is used replace all the occurrences of ‘old’ in string with ‘new’ or maximum occurrences if max is given.
  • upper()- This method is used to convert the lowercase letters in a string to uppercase.

If you have any queries? Mention them in the comments section and we will clarify you.

Python for DataScience


Python is the selection of information researchers. In nowadays python plays an important role to do their everyday exercises, as it has a differing scope of open-source libraries, and everything is free. The work of data scientists involves several interrelated activities, such as:

  • Accessing and manipulating data
  • Computing statistics
  • Creating visual reports on that data
  • Configuring predictive and explanatory models
  • Evaluating the models based on the additional data
  • Integrating the models into the production systems

If a data scientist wants to do some ad hoc analysis on data, he doesn’t write a Java code; the reason is java is too complicated for a data scientist to start programming. It has its own syntax and semantics, and every time there is a chance for developing a program in which one might run into a syntax or a semantic error, which nobody needs. Consequently, Pig and Hive were developed, however additionally we have Python in parallel, wherein you don’t need to compose a great deal of lines of code.

The only thing that you need to remember in Python is indentation. Whenever a code is being written, in this time one needs to take care of spacing. If the indentation (spacing) is not proper, the program would be failed. If you are running a ‘for loop’, anything within the ‘for loop’ has to come a few inches inside the ‘for loop’. All lines of code should have same indentation or should be in one line.


SciPy (pronounced as “sigh pie”) is Scientific Python which empowers the scientific analysis. It is a Python-based biological system of open-source software for mathematics, science, and engineering. We all have done differentiation, equation, etc. in mathematics, in school and college. Presently, how is it done in computers? It can be done in Octave as well, but Python provides us with SciPy which is the one that can perform such types of operations very easily. The Python that coordinates some libraries namely NumPy, SciPy library, Matplotib, IPython, Sympy, and pandas, and each one has its own role to play.

If you have any queries ? Specify them in the remarks area we will clarify you !..

Introduction to python IDE


Python IDE (Integrated Development Environment) is a code editor, which allows editing of code making use of a series of peripheral components and attachments. The code editor we are using which almost gives the same result.

Features of Python IDE

  • It has  an ordinary text-editor
  • It offers a variety of language with specific shortcut editing functions.
  • Very fast and comfortable to use
  • Python is also an interpreter

PyCharm is one of the Python IDE code editors that are generally used by programmers.

Downloading PyCharm

The Free Community Edition of PyCharm can be downloaded from the link below:

Starting Python

To start Python, you just need to type Python in your terminal command line and after that press enter.

The $ sign denotes the start of a terminal command line, and then the # sign denotes a comment. Python ignores anything written on the right side of # sign on a given line.

Using the Interpreter

  • In addition to being a programming language, Python is also an interpreter. It reads other Python programs and commands, and executes them.
  • Python programs are compiled automatically before being scanned by the interpreter. The hidden scanning process makes Python faster than a pure interpreter.
  • Once you’re inside Python, you can type commands at your own will.
  • Quantities stored in memory are not displayed by default
  • If the quantity is stored in memory, typing its name will display it.
  • To exit the interpreter, you need to press [Ctrl + D]

If you have any queries? Mention them in the comments section and we will clarify you.

Python Database Access


The Python standard for database interfaces is the Python DB-API. Most Python database interfaces adhere to this standard. Python Database API supports a wide range of database servers such as −

  • GadFly
  • MySQL
  • MySQL
  • PostgreSQL
  • Microsoft SQL Server 2000
  • Informix
  • Interbase
  • Oracle
  • Sybase

The DB API provides a minimal standard for working with databases using Python structures and syntax wherever possible. The MySQLdb module explains all concepts using MySQL. This API includes the following:

  • Importing the API module.
  • Acquiring a connection with the database.
  • Issuing SQL statements and stored procedures.
  • Closing the connection.

What is MySQL db?

MySQLdb is an interface for connecting to a MySQL database server from Python which implements the Python Database API v2.0 and it is built on the top of the MySQL C API.

How do I Install MySQLdb?

Before proceeding, make sure the MySQLdb is installed on the machine. Just type the following in Python script and execute it:


Import MySQLdb

If it produces the below result, it means MySQLdb module is not installed:

Traceback (most recent call last):

Import MySQLdb

ImportError: No module named MySQLdb

Database Connection

Before connecting to the MySQL database, check the followings −

  • Create a database TESTDB.
  • Create a table EMPLOYEE in TESTDB.
  • This table has fields such as FIRST_NAME, LAST_NAME, AGE, SEX and INCOME.
  • User ID “testuser” and password “test123” are set to access TESTDB.
  • Python module MySQLdb is installed properly on the machine.

While running this script, the below result would be produced.

Database version: 5.0.45

Creating Database Table

Once a database connection is established, we are ready to create tables or records into the database tables using execute method of the created cursor.

INSERT Operation

It is required when we want to create the records into a database table.

READ Operation

Fetch some useful information from the database. Once our database connection is established and then makes a query into this database.

  • fetchone() – Fetches the next row of a query result set. A result set is an object that is returned when a cursor object is used to query a table.
  • fetchall() –Fetches all the rows in a result set. If some rows have already been extracted from the result set, then it retrieves the remaining rows from the result set.
  • Rowcount – This is a read-only attribute, returns the number of rows that were affected by an execute() method.

Update Operation

Used to update one or more records that are already available in the database.

DELETE Operation

Used to delete some records from the database.

Performing Transactions

It is a mechanism that ensures data consistency having the following properties:

  • Atomicity –Either a transaction completes or nothing happens at all.
  • Consistency –A transaction must start in a consistent state and leave in a consistent state.
  • Isolation –Intermediate results of a transaction are not visible outside the current transaction.
  • Durability –Once a transaction was committed, the effects are persistent, even after a system failure.

The Python DB API 2.0 provides two methods to either commit or rollback a transaction.

COMMIT Operation

It gives a green signal to database to finalize the changes, and after this operation, no change can be reverted back.

ROLLBACK Operation

Revert back the changes completely by using use rollback() method.

Disconnecting Database

By using the close() method to disconnect the Database connection.

Handling Errors

There are many sources of errors. The DB API defines a number of errors that must exist in each database module. The exceptions are mentioned below.

  • Warning – Used for non-fatal issues.
  • Error – Base class for errors.
  • Interface Error – Used for errors in the database module not for the database itself.
  • Database Error – Used for errors in database.
  • Data Error – Subclass of database error which refers the errors in the data.
  • Operational Error – Refers the loss of connection to the database that are outside of control of the python scripter.
  • Integrity Error – Damage the relational integrity such as uniqueness constraints or foreign keys.
  • Internal Error – Refers to the errors internal to the database module.
  • Programming Error – Refers to the errors such as bad table name.
  • Not Supported Error – Refers that trying to call unsupported functionality.


Python Network Programming


Python provides two levels of access to network services. At a low level, we can access the basic socket support in the underlying operating system, which would allows to implement clients and servers for both connection-oriented and connectionless protocols.

Python also has libraries that would provide higher-level access to specific application-level network protocols, such as FTP, HTTP, and so on.

What is Sockets?

Sockets are the endpoints of a bidirectional communications channel. Sockets may communicate within a process, between processes on the same machine, or between processes on different continents.

Sockets would be implemented over a number of different channel types such as Unix domain sockets, TCP, UDP, and so on. The socket library provides specific classes for handling the common transports as well as a generic interface for handling the rest.

Socket Module

To create a socket, we must use the socket.socket() function available in socket module, which has the general syntax that are given as follows:

s = socket.socket (socket_family, socket_type, protocol=0)

The parameters can be described as follows

socket_family – This is either AF_UNIX or AF_INET.

socket_type – This is either SOCK_STREAM or SOCK_DGRAM.

protocol – This is usually left out, defaulting to 0.

Server Socket Methods

s.bind() – This method is used to binds the address (hostname, port number pair) to socket.
s.listen() – This method is used to sets up and start TCP listener.

s.accept() – This method passively accept TCP client connection, waiting until connection arrives (blocking).

Client Socket Methods

s.connect()This method actively initiates TCP server connection.

General Socket Methods

s.recv() – This method receives TCP message

s.send() – This method transmits TCP message

s.recvfrom() – This method receives UDP message

s.sendto() – This method transmits UDP message

s.close() – This method closes socket

socket.gethostname() – This method would returns the hostname.

A Simple Server

To write Internet servers, we use the socket function available in socket module to create a socket object. A socket object is used to call other functions to setup a socket server.

Call the bind(hostname, port) function to specify a port for the service on the given host.

Next, call the accept method of the returned object. This method waits until a client connects to the port specified, and then returns a connection object that represents the connection to that client.

A Simple Client

Write a very simple client program which opens a connection to a given port 12345 and given host. This is very simple to create a socket client using Python’s socket module function.

The socket.connect(hostname, port) opens a TCP connection to hostname on the port. Once the socket is open, read from it like any IO object. When done, remember to close it, as to close a file.




Benefits of Python

Benefits of Python


Python is a dynamic object-oriented programming language that would be compared with Java and Microsoft’s .NET-based languages as a general-purpose substrate for many kinds of software development. It offers strong support for integrating with other technologies, higher programmer productivity throughout the development life cycle, and is particularly well suited for large or complex projects with changing requirements.

Python is the most rapidly growing open source programming language. According to InfoWorld its user base is nearly doubled in 2004, and currently includes 14% of all programmers.

Python is being used in mission critical applications in the world’s largest stock exchange, forms the basis for high end newspaper websites, run on millions of cell phones, used in industries as diverse as ship building, feature length movie animation, and air traffic control.
Python is available for most operating systems, including Windows, UNIX, Linux, and Mac OS.


Key Strengths

Python’s clean object-oriented design which would extensively support libraries and offer two to ten fold. The programmer productivity seen with languages like C, C++, C#, Java, VB, and Perl.

Python’s key strengths


Of all types, including Enterprise Application Integration (EAI). Python makes it easy to develop Web services, which would invoke COM or CORBA components, calls directly to and from C, C++, or Java code (via Jython), provides powerful process control capabilities, implements all common internet protocols and data formats, processes XML and other markup languages, that would be embedded as a scripting language, and runs from the same byte code on all modern operating systems.


Network intensive applications

Complex multi-protocol network applications that would build a Twisted, a development framework well suited for running large number of concurrent network, database, and inter-process communication links within the same process.


Web development

From simple CGI scripting to high-end web application development with mega-frameworks such as Django and TurboGears, the Zope application server, Plone content management system, Quixote web application framework, or even a home-grown solution based on Python’s extensive that is easy to use standard libraries. Python provides interfaces to most databases, powerful text processing and document processing facilities, and plays well with other web technologies.


Numeric and scientific applications

Use of the Python Imaging Library, VTK and MayaVi 3D Visualization Toolkits, Numeric Python, Scientific Python and many other tools available for numeric and scientific applications. Many of these are supported by the Enthought Python Distribution.


Application scripting

Snap with Python’s tight integration with C/C++ and Java. Python was designed from the ground up to be embeddable and serves as an excellent choice as a scripting language for customization or extension of larger applications.


Software Testing

Benefits from Python’s strong integration and text processing capabilities, and Python come with its own unit testing framework.


Desktop development

Using wxPython, PyQt, or PyGtk for high-quality GUI applications. Protect the investment by basing on open technologies, with deployment to most operating systems. Support for other GUI frameworks, such as MFC, Carbon, Delphi, X11, Motif, and Tk, is also available.



Python is quick and easy, and often results in development of the final system. The agile nature of the language and the ease of refactoring code make for rapid development directly from the initial prototype.


The Open Source Advantage

It would be developed as open source by thousands of contributors from around the world; Python is very well designed, fast, robust, portable, and scalable. With an uncluttered, easy-to-learn syntax and well-developed advanced language features, Python often exceeds the capabilities of comparable commercially available solutions.

The open source license for Python allows unrestricted use, modification, and redistribution of the language or anything that is based on it, commercially or otherwise. Full source is available and there are no license costs. Support is available for free, from a rich set of internet-based resources, and from organizations in the business of providing paid support to Python users.





Python in Linux admin

Python is a must learn programming language for Linux admin. Almost more than 20 percent of Linux job require Python programming and also Software developers have a great asset to mention on their CV.

Python in Automation testing professionals

For software testing professional Python skills are must which is required to write test cases and run to check software performance, build test automation framework and also requirement for mobile and device testing professionals.

Python in Database programming

Used in developing Database and rectifies the error, add efficiency to work and improves the productivity of Database developers.

Python in Develop Complex website and systems

It has an own frameworks, Django which is MVC based framework used in developing complex and large websites specially used to develop social networking sites. Most popular Social sites like Facebook and question answer website Quora has been developed using Python programming language. As a Python programmer are getting paid more compared to other language programmers. There was a huge community built around python. Python programming is one of the most taught programming languages in US which is easy to learn and more efficient in solving complex problems.

Major Internet and mobile companies like Yahoo, Google, Facebook, Nokia, NASA and many others major market players use Python programming to develop easy to use simplified web application and systems. Along with these Python is also core to Linux must for all Linux programmer and system developer.

Python is an open source programming language and used to develop simple to complex functions. Python programming is used to develop websites, develop database systems, Device and software testing and also used to develop system programming.


Python has been voted as most favorite programming language beating C, C++ and java programming. Python programming is open source programming language and used to develop all kind of application.

Python is being used as worldwide in a wide range of application development and system development programming language. Big brands and search engine giants are using python programming to make their task easier. Google, Yahoo, Quora, Facebook are using python programming to solve their complex programming problems.

Python programming is versatile, robust and comprehensive. Python is high level programming language and easy to learn as well as it reduces the coding effort compare to other programming languages.

Python programming is used to write test scripts and test mobile devices performance. In these days, python is one of the most versatile languages. Nowadays Python programmers are most demandable in IT industry and get paid more compare to other language programmer.

Python programming language helps solve complex problem quickly and integrate with system more effectively. Python is involved in lots of environment such as system development, networking, database development, Device and automation testing and many more and its skill is must as a programmer to grow in career. Thus feature of Python programming language is bright and secured.