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
Programming Articles - Page 2495 of 3363
2K+ Views
In this article, we will learn about iterating/ traversing over characters of a string in Python 3.x. Or earlier.The string is a collection of characters which may contain spaces, alphabets or integers. They can be accessed using indexes or via references . Some commonly implemented methods are shown below.Method 1 − The direct itertor without indexingExamplestring_inp = "tutorialspoint" # Iterate over the string for value in string_inp: print(value, end='')Method 2 − The most common way using index based accessExamplestring_inp = "tutorialspoint" # Iterate over the string for value in range(0, len(string_inp)): print(string_inp[value], end='')Method 3 − The ... Read More
196 Views
This function is helpful in converting the letters of a word into lowercase. When applied to two strings it can match their values irrespective of the type up of the case of the letters.Applying casefold()The below example we apply the casefold() function to a string and the result comes out in all lower case letters.Examplestring = "BestTutorials" # print lowercase string print(" lowercase string: ", string.casefold())OutputRunning the above code gives us the following result −Lowercase String: besttutorialsComparing using casefold()We can compare two strings which have same letters but in different cases after applying the casefold() function. The result of the ... Read More
247 Views
The callable() function in python is part of its standard library which returns true if the object is callable and returns false if it is not.The object itself should have a call method to be callable. For example if we just declare a variable with value, it is not callable, but if we declare a function then it becomes callable.Callable ObjectBelow we declare a function which is callable. That can be verified by actually making a call to the function, as well as checking through the callable function.Exampledef func_callable(): x = 3 y = 5 z = ... Read More
443 Views
In this article, we will learn about iterating/traversing over a list in Python 3.x. Or earlier.A list is an ordered sequence of elements. It is a non-scalar data structure and mutable in nature. A list can contain distinct data types in contrast to arrays storing elements belonging to the same data types.Method 1 − Using iterable without indexExamplelist_inp = ['t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o', 'i', 'n', 't'] # Iterate over the list for value in list_inp: print(value, end='')Method 2 − Using general way via indexExamplelist_inp = ['t', 'u', 't', 'o', 'r', 'i', ... Read More
1K+ Views
The bin() function converts a decimal to binary. You can use a positive or negative integer as the parameter to be converted.SyntaxBelow is the syntax of the function.bin(n) Parameters : an integer to convert Return Value : A binary string of an integer or int object. Exceptions : Raises TypeError when a float value is sent as argument.In the below example we convert a positive and a negative integer to binary. The results come out with a prefix of 0b to indicate that the number is a binary representation.Examplen = input("Enter an integer :") dec_number = int(n) bin_number = bin(dec_number) ... Read More
7K+ Views
Sometimes we need to go through the elements of a list in backward order. To achieve this we need to read the last element first and then the last but one and so on till the element at index 0. Various python programming features can be used to achieve this.Using range(N, -1, -1)We are using the range function but starting with the position -1. This value helps us read the list from the last index value also we iterate through steps of -1. In the below example we start at a position which is measured by taking the length of ... Read More
2K+ Views
In this article, we will learn about isupper(), islower() ,upper() , lower() function in Python 3.x. or earlier.These are the functions that can be used on strings and related types. They are included in Python Standard Library.All the functions accept no arguments. The isupper() & islower() return boolean values whereas the upper() & lower() function returns strings either in uppercase or lowercase.Now let’s see the implementation using an exampleExamplestring = 'tutorialspoint' # checking for uppercase characters print(string.isupper()) # checking for lowercase characters print(string.islower()) # convert to uppercase characters print(string.upper()) # convert to lowercase characters print(string.lower())OutputFalse True ... Read More
1K+ Views
ASCII is abbreviated from of American Standard Code for Information Interchange. It is a character encoding standard. For example the ASCII value of English alphabet A is 65. Python provides this function to get the printable representation of an object. It takes one parameter which is an object that can be a list, strings, tuple etc. The output of the function is the hex representation. The non-ascii characters can be escaped using \x, \u or \U escapes.SyntaxThe syntax is −Syntax: ascii(object)ExamplePrinting strings with individual characters and multiple characters.# Individual Characters print(ascii("Ω")) print(ascii("θ")) # A string int multiple characters print(ascii("TΨtΦrial"))OutputRunning the ... Read More
270 Views
In this article, we will learn about how we can implement isdisjoint() function on set() data type. This function checks whether the sets passed as arguments have any element in common . In case any element is found, False is returned and True otherwise.The isdisjoint() function can take lists, tuples & dictionaries as input arguments in addition to set inputs. THses types are implicitly converted to set type by the Python interpreter.Syntax.isdisjoint()Return valueBoolean True/FalseNow let’s consider an illustration related to the implementationExample#declaration of the sample sets set_1 = {'t', 'u', 't', 'o', 'r', 'i', 'a', 'l'} set_2 = {'p', 'o', ... Read More
213 Views
In this article, we will learn about the iintersection_update() in Python to find out common elements in n arrays.The problem is that we are given an array containing lists, find all common elements in given arrays?Algorithm1.Initializingres with the first list inside the array 2.Iterating through the array containing lists 3.Updating the res list by applying intersection_update() function to check the common elements. 4.Finally returning the list and display the output by the help of the print statement.Now let’s take a look at its implementationExampledef commonEle(arr): # initialize res with set(arr[0]) res = set(arr[0]) # new value will get ... Read More