
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 10476 Articles for Python

434 Views
Python 3.0 was released in December 2008. It was designed to rectify certain flaws in earlier versions. Python 3.0 doesn’t provide backward compatibility. That means a Python program written using version 2.x syntax doesn’t execute under the Python 3.x interpreter. Version 2.7 is the final major release in the Python 2.x series. The guiding principle of Python 3 was: "reduce feature duplication by removing old ways of doing things". Although there are quite a few differences in usage of these two versions, the most obvious ones are mentioned below - Print Statement Vs Function print is a keyword in Python ... Read More

3K+ Views
Binary file is a file that consists of a series of 1's and 0's. This is typically used to represent data such as images, audio, video, etc. To open the binary files in read and write mode, Python provides an in-built function, which is the open() function. The open() Function The Python open() function is a built-in function that is used to open a file. This method accepts a string value representing a file path (or, name) as a parameter and returns the object of the specified file. In addition to the file path, we can also pass another parameter named ... Read More

2K+ Views
In Python, you can open a file for both reading and writing using the built-in open() function. This is essential when you want to manipulate a file's content without needing to close and reopen it repeatedly. This mode allows us to read from and write to the file simultaneously, but it will raise an error if the file does not exist. We can also use Write and Read (w+) mode, which will truncate the file. Opening a File in Read and Write Mode To open a file for reading and writing, you can use the Read and Write Mode ('r+'). ... Read More

3K+ Views
In Python, to open a binary file in append mode, we can use the open() function with the mode set to ab. This allows us to open an existing file or create a new one. Using the open() function with the appropriate mode enables us to work with the file as needed. Mode 'ab' In the mode 'ab', the 'a' stands for append mode, which allows us to add new data to the end of the file without truncating its existing content. The 'b' stands for binary mode, used when handling files containing non-text data or non-readable characters. Binary files ... Read More

569 Views
Developers have to interact with users to get data or provide some sort of result. These days, most programs use a dialog box to give some type of input. In Python, there are two in-built functions to read the input from the user − input() raw_input() Python input() Function In Python, the input() is a user-defined function used to take the values from the user. Whenever we use this function the program will stop till the user provides an input value. There is a slight ... Read More

329 Views
The function close() closes an open file. For example: f = open('my_file', 'r+') my_file_data = f.read() f.close() The above code opens 'my_file'in read mode then stores the data it reads from my_file in my_file_data and closes the file. When you open a file, the operating system gives a file handle to read/write the file. You need to close it once you are done using the file. If your program encounters an error and doesn't call f.close(), you didn't release the file. To make sure it doesn't happen, you can use with open(...) as syntax as it automatically closes files regardless of whether ... Read More

448 Views
In Python 2, there was an alternative syntax for using the print statement for printing that involved using the >> operator, also known as the right shift operator. However, this syntax has been deprecated and removed in Python 3. Therefore, if you see code that uses print >> syntax, it is likely written in Python 2 and will not work in Python 3. The correct syntax in Python 2 for redirecting the output of the print statement to a file-like object is using the print statement followed by the >> operator and the file object. Here are ... Read More

864 Views
In Python, among several functions and other tools that are used to achieve certain functionalities, the print() function happens to be a basic tool for displaying output to the console or terminal. This function allows programmers to achieve several tasks such as, among others, presenting information, messages, variables, and other data to users or for debugging purposes. In this article, we will investigate in detail the functionality and usage of the print() function in Python, through several code examples followed by comprehensive explanations. This will help you to add one more Python skill to your repertoire of code expertise ... Read More

809 Views
The basic way to do output to screen is to use the print statement.>>> print 'Hello, world' Hello, worldTo print multiple things on the same line separated by spaces, use commas between them. For example:>>> print 'Hello, ', 'World' Hello, WorldWhile neither string contained a space, a space was added by the print statement because of the comma between the two objects. Arbitrary data types can also be printed using the same print statement, For example:>>> import os >>> print 1, 0xff, 0777, (1+5j), -0.999, map, sys 1 255 511 (1+5j) -0.999 Objects can be printed on the same line ... Read More

2K+ Views
Currently you cannot add namespaces to XML documents directly as it is not yet supported in the in built Python xml package. So you will need to add namespace as a normal attribute to the tag. For example,import xml.dom.minidom doc = xml.dom.minidom.Document() element = doc.createElementNS('http://hello.world/ns', 'ex:el') element.setAttribute("xmlns:ex", "http://hello.world/ns") doc.appendChild(element) print(doc.toprettyxml())This will give you the document,