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
Python Articles
Page 680 of 855
Autorun a Python script on windows startup?
Making a Python script run automatically when Windows starts can be useful for background tasks, monitoring applications, or system utilities. There are two main approaches: using the Startup folder or modifying the Windows Registry. Method 1: Using Windows Startup Folder The simplest approach is to place your Python script (or a shortcut to it) in the Windows Startup folder. Windows automatically runs all programs in this folder during boot. Startup Folder Location C:\Users\current_user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ Steps to Add Script 1. Navigate to the Startup folder (you may need to enable "Show hidden files" ...
Read MoreBuilt-in Dictionary Functions & Methods in Python
Python dictionaries come with built-in functions and methods that make working with key-value pairs efficient and straightforward. These functions help you manipulate, query, and transform dictionary data. Built-in Dictionary Functions Python provides several built-in functions that work with dictionaries ? len() Function student = {'name': 'Alice', 'age': 20, 'grade': 'A'} print(len(student)) 3 str() Function student = {'name': 'Alice', 'age': 20} print(str(student)) print(type(str(student))) {'name': 'Alice', 'age': 20} type() Function student = {'name': 'Alice', 'age': 20} print(type(student)) ...
Read MoreProperties of Dictionary Keys in Python
Dictionary values have no restrictions. They can be any arbitrary Python object, either standard objects or user-defined objects. However, the same is not true for dictionary keys. There are two important points to remember about dictionary keys: No Duplicate Keys Allowed More than one entry per key is not allowed. When duplicate keys are encountered during assignment, the last assignment wins ? # Duplicate keys - last value overwrites previous ones student = {'Name': 'Zara', 'Age': 7, 'Name': 'Manni'} print("student['Name']:", student['Name']) print("Full dictionary:", student) student['Name']: Manni Full dictionary: {'Name': 'Manni', 'Age': 7} ...
Read MoreBuilt-in Tuple Functions in Python
Python provides several built-in functions to work with tuples. These functions help you perform common operations like finding length, maximum/minimum values, and converting sequences to tuples. len() Function The len() function returns the total number of elements in a tuple ? numbers = (1, 2, 3, 4, 5) fruits = ('apple', 'banana', 'orange') empty_tuple = () print("Length of numbers:", len(numbers)) print("Length of fruits:", len(fruits)) print("Length of empty tuple:", len(empty_tuple)) Length of numbers: 5 Length of fruits: 3 Length of empty tuple: 0 max() Function The max() function returns the ...
Read MoreNo Enclosing Delimiters in Python
In Python, when you write multiple objects separated by commas without any enclosing delimiters (like brackets [] for lists or parentheses () for tuples), Python automatically treats them as tuples. This behavior is called implicit tuple creation. Basic Tuple Creation Without Delimiters Here's how Python interprets comma-separated values without delimiters ? # Multiple values without delimiters create a tuple data = 'abc', -4.24e93, 18+6.6j, 'xyz' print(data) print(type(data)) ('abc', -4.24e+93, (18+6.6j), 'xyz') Tuple Unpacking This implicit tuple creation is commonly used with tuple unpacking ? # Tuple unpacking ...
Read MoreBasic Tuples Operations in Python
Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string. In fact, tuples respond to all of the general sequence operations we used on strings in the prior chapter − Basic Tuple Operations Python Expression Results Description ...
Read MoreDelete Tuple Elements in Python
Tuples are immutable in Python, meaning you cannot delete individual elements from an existing tuple. However, you can create a new tuple with unwanted elements removed, or delete the entire tuple variable using the del statement. Why You Cannot Delete Individual Elements Tuples are immutable data structures, so operations like del tuple[index] will raise a TypeError ? subjects = ('physics', 'chemistry', 'math', 'biology') # This will raise an error try: del subjects[1] except TypeError as e: print(f"Error: {e}") Error: 'tuple' object doesn't support item ...
Read MoreBuilt-in List Functions & Methods in Python
Python provides numerous built-in functions and methods to work with lists efficiently. These functions help perform common operations like finding length, maximum/minimum values, and converting sequences to lists. Built-in List Functions Python includes the following list functions ? Sr.No Function with Description ...
Read MoreBasic List Operations in Python
Lists are sequence objects in Python that support the same fundamental operations as strings. They respond to the + and * operators for concatenation and repetition, except the result is a new list rather than a string. Lists support all general sequence operations, making them versatile for data manipulation and processing tasks. Length Operation Use len() to get the number of elements in a list − numbers = [1, 2, 3] print("Length of list:", len(numbers)) Length of list: 3 Concatenation with + Operator Combine two lists using the + ...
Read MoreBuilt-in String Methods in Python
Python provides a rich set of built-in string methods for manipulating and working with text data. These methods cover everything from case conversion and formatting to searching and validation. Case Conversion Methods Methods for changing the case of characters in strings ? text = "hello WORLD" print("Original:", text) print("capitalize():", text.capitalize()) print("upper():", text.upper()) print("lower():", text.lower()) print("title():", text.title()) print("swapcase():", text.swapcase()) Original: hello WORLD capitalize(): Hello world upper(): HELLO WORLD lower(): hello world title(): Hello World swapcase(): HELLO world String Validation Methods Methods that return True or False based on string content ...
Read More