![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 27104 Articles for Server Side Programming
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
907 Views
The difference between using ', ' and 'as' in except statements, is as follows:Both ', ' and 'as' are same functionality wise; but their use depends on the python versions as follows.In Python 2.5 and earlier versions, use of the 'comma' is recommended since 'as' isn't supported.In Python 2.6+ versions, both 'comma' and 'as' can be used. But from Python 3.x, 'as' is required to assign an exception to a variable.As of Python 2.6 using 'as' allows us an elegant way to catch multiple exceptions in a single except block as shown belowexcept (Exception1, Exception2) as erris any day better ... Read More
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
26K+ Views
An exception is an unexpected error or event that occurs during the execution of program. The difference between an error and an exception in a program is that, when an exception is encountered, the program deflects from its original course of execution whereas when an error occurs, the program is terminated. Hence, unlike errors, an exception can be handled. Therefore, you won't have a program crash. However, in some cases of Python, the exception might not cause the program to terminate and will not affect the direction of execution hugely. Therefore, it is best to ignore such kind of exceptions. ... Read More
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
10K+ Views
The looping technique in Python transforms complex problems into simple ones. It allows us to change the flow of the program so that instead of writing the same code over and over, we can repeat it a limited number of times until a certain condition is satisfied. For example, if we need to display the first ten natural numbers, we can do it inside a loop that runs up to ten iterations rather than using the print command ten times. Python offers three ways to loop a block of code in a program: using for loops, while loops and nested ... Read More
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
2K+ Views
Before we understand how to catch a Python exception in a list comprehension, let us first learn what a list comprehension is. List comprehension is a statement that allows you to create a list and execute a for loop, all in a single sentence. This also allows the lists to be created from other iterables like tuples, strings, arrays, lists, and so on. The syntax of list comprehension is given below − List = [expression(element) for element in list if condition] The python list and list comprehension capability, which may be used inside a single line of code to ... Read More
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
15K+ Views
Variables are defined as the containers used to store some data. They represent a memory location. Any type of data or value can be stored in a variable in Python, including integers, strings, float, Boolean etc. In Python, a variable's data type does not need to be specified when it is defined in a program. However, before any function or application can use variables, they must be defined first. It can be done by simply assigning a value to a name as shown below − x = 5 Here, ‘x’ is the name of a variable. Also, since x ... Read More
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
3K+ Views
We will learn about what an exception is before learning how to print python exceptions. An exception occurs when a program fails to execute in the direction it was intended to be. Python throws exceptions when unexpected errors or events occur. It is common for exceptions to be both valid and invalid. Errors and exceptional conditions can be managed in a program through exceptions in a variety of ways. The exception handling technique can be used when you suspect your code may create an error. This can prevent the software from crashing. Common Exceptions IOError (Input Output Error) − ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
129 Views
For the above module, we need to prepare following setup.py script −from distutils.core import setup, Extension setup(name='helloworld', version='1.0', \ ext_modules=[Extension('helloworld', ['hello.c'])])Now, we use the following command,$ python setup.py installOnce we install the extension, we would be able to import and call that extension in our Python script test.py and catch the exception in it as follows −#test.py import helloworld try: print helloworld.helloworld() except Exception as e: print str(e)This would produce the following result −bad format char passed to Py_BuildValue
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
3K+ Views
The purpose of a function is to perform a specific task using code blocks. In programming, functions save time by eliminating unnecessary and excessive copying and pasting of code. Hence, a function will be of great use if there is a common action that needs to be performed in different places and often. The only thing you'll need to do is update that specific function, if you want to make a change. As a result, you no longer have to copy and paste the same piece of code that is scattered throughout your program in order to find it. This ... Read More
![Alekhya Nagulavancha](https://www.tutorialspoint.com/assets/profiles/535884/profile/60_4128029-1665726265.jpg)
5K+ Views
In Python, functions are usually called by passing none, one or more arguments to it. There are two types of arguments that can be used − Positional arguments Keyword arguments. Positional arguments depend on the order they are passed to a function; they are the more common type of arguments used in programming languages. Whereas, keyword arguments are passed as key-value pairs so that the arguments are mapped to a key using the “=” operator which allows the Python interpreter to ignore the positions. In this article, we will be discussing about keyword parameters/arguments and how to pass ... Read More