Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to create an empty list in Python?
In Python, a list is one of the built-in data types. A Python list is a sequence of items separated by commas and enclosed in square brackets [ ]. The items in a Python list need not be of the same data type. In this article, we will discuss different ways to create an empty list in Python. Using Square Brackets This is the simplest and most common way to create an empty list using square brackets []. An empty list means the list has no elements at the time of creation, but we can add items ...
Read MoreHow to convert a single character to its integer value in Python?
In Python, the ord() function converts a single character to its corresponding ASCII (American Standard Code for Information Interchange) or Unicode integer value. The ord() function raises a TypeError if you pass a string with more than one character. Syntax ord(character) Parameters: A single character (string of length 1) Return Value: Integer representing the Unicode code point of the character Converting a Single Character to Integer Here's how to convert a character 'A' to its Unicode integer value ? my_char = 'A' result = ord(my_char) print("Unicode of 'A':", result) # ...
Read MoreHow can I convert Python strings into tuple?
Converting Python strings into tuples is a common operation with multiple approaches depending on your needs. You can create a tuple containing the whole string, split the string into individual characters, or parse delimited strings into separate elements. Using Comma to Create Single-Element Tuple The simplest way is to add a comma after the string variable to treat the entire string as a single tuple element ? s = "python" print("Input string:", s) t = s, print("Output tuple:", t) print("Type:", type(t)) Input string: python Output tuple: ('python', ) Type: ...
Read MoreHow to create a dictionary with list comprehension in Python?
Python provides several ways to create dictionaries using list comprehension. The dict() method combined with list comprehension offers an elegant approach to generate key-value pairs dynamically. Syntax The basic syntax for creating a dictionary with list comprehension ? # Using dict() with list comprehension dict([(key, value) for item in iterable]) # Direct dictionary comprehension (alternative) {key: value for item in iterable} Using Unicode Characters as Keys Create a dictionary where keys are Unicode characters and values are their corresponding integers ? dict_obj = dict([(chr(i), i) for i in range(100, 105)]) ...
Read MoreWhat does ** (double star) and * (star) do for parameters in Python?
While creating a function, the single asterisk (*) is used to accept any number of positional arguments, and the double asterisk (**) is used to accept any number of keyword arguments. These operators provide flexibility when you don't know in advance how many arguments will be passed to your function. Using * (Single Asterisk) for Positional Arguments The single asterisk (*) collects extra positional arguments into a tuple. By convention, this parameter is named *args. Example Create a function that accepts an arbitrary number of positional arguments ? def sum_numbers(*args): ...
Read MoreHow to pass Drop Down Box Data to Python CGI script?
Drop down boxes are useful HTML form elements when you have multiple options but only want to allow selection of one or two items. Here's how to pass dropdown data to a Python CGI script and process it server-side. HTML Form with Dropdown First, create an HTML form with a dropdown (select) element ? Maths Physics Chemistry This creates a dropdown with ...
Read MoreHow to pass Text Area Data to Python CGI script?
The TEXTAREA element allows users to input multiline text data that can be processed by a Python CGI script. This is useful for forms that need to collect longer text content like comments, descriptions, or messages. HTML Form with TEXTAREA Here is the HTML code for creating a form with a TEXTAREA element ? Type your text here... The result of this code is the following form ? Type your text here... Submit Python CGI Script Below is the textarea.py script to handle ...
Read MoreHow to pass Radio Button Data to Python CGI script?
Radio buttons allow users to select exactly one option from a group of choices. When working with CGI (Common Gateway Interface) in Python, you can easily retrieve and process radio button data using the cgi module. HTML Form with Radio Buttons Here is example HTML code for a form with two radio buttons − Maths Physics The result of this code is the following form − Maths Physics [Select Subject] Python CGI Script Below is radiobutton.py script to handle input given by web ...
Read MoreHow to process a simple form data using Python CGI script?
Python CGI (Common Gateway Interface) allows web servers to execute Python scripts and process form data. When a user submits an HTML form, the CGI script can retrieve and process the submitted data. HTML Form Setup First, create an HTML form that sends data to a Python CGI script ? FirstName: LastName: This form collects first and last names, then sends the data to getData.py using the POST method. Python CGI Script Create the getData.py script to process ...
Read MoreHow to send the result of Python CGI script to the browser?
A Python CGI script runs on a web server and sends dynamic HTML content to the browser. To send results from your CGI script to the browser, you need to output proper HTTP headers followed by HTML content. Basic CGI Response Structure Every CGI script must start with a content-type header, followed by a blank line, then the HTML content − #!/usr/bin/env python3 import cgi # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from HTML form fields first_name = form.getvalue('first_name') last_name = form.getvalue('last_name') # Send HTTP header print("Content-type:text/html") print() ...
Read More