Python Archive
Set Operations using Functions and Operatorss: Set Object is providing pre-defined functionality to perform all mathematical set operations such as union, intersection, difference, symmetric_difference and so one. We can also perform the same set operations …
type(): A pre-defined function that returns identity of class if we specify an Object. We can create collection object in 2 ways. List construction: #Tuple construction: Set construction: Empty set can be constructed only through …
What is dictionary? A dictionary is an ordered collection. Dictionary is Mutable(changeable). Dictionary elements are key-value pairs. A Dictionary in python is declared by enclosing a comma-separated list of key-value pairs using curly braces(“{}”). Key: …
Dictionary object is providing set of functions which are used process elements of that dictionary. Code: Output:
We can iterate the dictionary using keys. For loop can iterate all keys of input dictionary. Output: Format the above program using string format specifiers: Output:
Update(): A pre-defined method is used to update the dictionary Output: Built-in Functions with Dictionary all() : Return True if all keys of the dictionary are true (or if the dictionary is empty). any() : …
Files: We can store the information of application in 2 ways permanently File System Database management system Database is structured and object oriented; hence we can store and process the data more effectively. File system …
Opening a file in read mode: After working with any resource(file, database, server…) from the application must be released manually(closing statements) Improper shutdown of resources results loss of data. Code: Reading information from the file: …
Read file character by character: Read() function return the complete data as object. We can process the data object character by character using for loop. We can easily iterate the file using pre-defined for loop. …
How can we process the file line by line? For loop can iterate the file line by line by taking file object name directly as an input. read() method is not required to process the …