Posts Tagged with 'Python'
Python Program to Swap First Two Characters of Two Strings and Merge Them
String manipulation is an essential skill in Python programming, and today, we’ll explore a fun and creative problem! ✅ Problem Statement: Given two strings, we will: Swap the first two characters of each string. Combine …
Replace Repeating Characters in a String – Python Program
String manipulation is a fundamental concept in programming, and today, we’ll explore an interesting problem: ✅ Given a string, replace all occurrences of its first character with '$', except for the first occurrence. This simple …
Python Program to Extract First and Last Two Characters of a String
When working with strings in Python, there are times when you need to extract specific parts of a given string. In this tutorial, we will write a simple Python program that extracts the first two …
Determine the frequency of each character in a string.
You can determine the frequency of each character in a string using Python's collections.Counter or a simple dictionary. Method 1: Using collections.Counter (Efficient) from collections import Counter text = "hello world" print(dict(Counter(text))) #Output: {'h': 1, …
Count the length of a string
In Python, you can count the length of a string using the len() function. text = "Hello, World!" length = len(text) print("Length of the string:", length) # Output: Length of the string: 38 The len() …
How to use django sitemap Framework for https?
To ensure your Django sitemap uses HTTPS, you can specify the protocol by adding it as a class variable in your sitemap class. Solution: Define Protocol in Sitemap Class Django's sitemap framework uses 'http' as …
Python check the memory usage of an object
Python | Check the memory usage of an object >>> import sys >>> x = 100 >>> print(sys.getsizeof(x)) 28
Python Print String N times
Python | Print String N times >>> s = 'Python' >>> n = 5 >>> print(s * n) PythonPythonPythonPythonPython
python return multiple values from functions
Python | Return multiple values from functions >>> def A(): return 2, 3, 4 >>> a, b, c = A() >>> print(a, b, c) 2 3 4
Python join all items of a list to convert into a single string
Python | Join all items of a list to convert into a single string >>> x = ["Python", "Online", "Training"] >>> print(" ".join(x)) Python Online Training
Reversing a String in Python
Python | Reversing a String >>> x = 'PythonWorld' >>> print(x[: : -1]) dlroWnohtyP
Python In-place swapping of two numbers
Python | In-place swapping of two numbers >>> a, b = 10, 20 >>> print(a, b) 10 20 >>> a, b = b, a >>> print(a, b) 20 10
List the common security issues that can be avoided by using Django?
A few common security issues that can be avoided by using Django are: Clickjacking Cross-site scripting and SQL injection
What is the difference between Python array and Python list?
Difference between Python array and Python list Array Lists it is used to store only homogeneous data. The list is used to store heterogeneous data it occupies less amount of memory as the array stores …
Program to count the number of capital letters in a file?
Python program to count the number of capital letters in a file. with open(FILE_NAME) as my_file: count = 0 text = my_file.read() for character in text: if character.isupper(): count += 1 print(count)