• Q & A – Python Dictionary

    Q & A – Python Dictionary

    (1) What Is A Python Dictionary? How Does It Work? Python Dictionary objects are data types that are enclosed in curly braces ‘{}’ and have key and value pairs and each pair is separated by a comma. The dictionary is mapped. Meaning since it has key and value pair, a meaningful key can save a lot of trouble for coders, like using an address key to save all the addresses, an id key for all id’s and so on. Moreover, as of Python >3.6, dictionaries also preserve the order. Example-1 student = {‘Name’:’Subrat’, ‘Subject’:’Math’, ‘Mark’:88} print(student) {‘Name’: ‘Subrat’, ‘Subject’: ‘Math’,

    Read More

  • Q & A – Python Set

    Q & A – Python Set

    (1) What Is A Set Data Structure? A Set is an unordered collection data type that is iterable, mutable and has no duplicate elements.  Set is represented by { } (values enclosed in curly braces) The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set.  This is based on a data structure known as a hash table. Since sets are unordered, we cannot access items using indexes as we do in lists. Example-1 st = {1,4,2,5,1,3,3,4} print(st) {1, 2, 3, 4,

    Read More

  • Q & A – Python Tuple

    Q & A – Python Tuple

    (1) What Is A Tuple Data Structure? Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. Tuples are used to store multiple items in a single variable. A tuple is a collection which is ordered and unchangeable. Example-1 tp = (1,’abc’,4.5,[9,8]) print(type(tp)) print(tp) <class ‘tuple’> (1, ‘abc’, 4.5, [9, 8]) (2) Find The Size Of The Tuple In Python. getsizeof() Function can be used to get the size of the tuple. The getsizeof() function belongs to the python’s sys module. Example-1 import sys

    Read More

  • Q & A – Python List

    Q & A – Python List

    (1) Check If A List Contains An Element. The in operator will return True if a specific element is in a list. lst = ['Subrat','Arpita','Abhispa','Subhada'] 'Subhada' in lst True (2) How To Iterate Over 2+ Lists At The Same Time. You can zip() lists and then iterate over the zip object. A zip object is an iterator of tuples. Below we iterate over 3 lists simultaneously and interpolate the values into a string. name = ['Snowball', 'Chewy', 'Bubbles', 'Gruff'] animal = ['Cat', 'Dog', 'Fish', 'Goat'] age = [1, 2, 2, 6] z = zip(name, animal, age) for i, j, k in z: print(f"Name: {i} Animal: {j} Age: {k}")

    Read More

  • Q & A – Python Numbers

    Q & A – Python Numbers

    (1) Check If A Number Is Positive, Negative or 0. num = float(input(‘Enter A Number ‘)) if num > 0: print(‘Positive Number’) elif num < 0: print(‘Negative Number’) else: print(‘Zero’) (2) Check If A Number Is Odd or Even. num = float(input(‘Enter A Number’)) if num % 2 == 0: print(‘Even Number’) else: print(‘Odd Number’) (3) Check A Year Is Leap Year Or Not. We have discussed above, we know that because the Earth rotates about 365.242375 times a year but a normal year is 365 days, something has to be done to “catch up” the extra 0.242375 days a

    Read More

  • Q & A – Python String

    Q & A – Python String

    (1) What Is A String Datatype? A String is a collection of a sequence of characters. A String can contain Alphabetic, Numeric, or Special characters. A String variable is enclosed within a single(”) or double quote(“”). A String type in Python is of the ‘str’ type. Example-1 name = 'Subrat Kumar Sahoo' print(name) Subrat Kumar Sahoo Example-2 password = "hallo@123" print(password) hallo@123 Example-3 country = 'India' print(country) India (2) How To Check Existence Of A Character Or A Sub-string In A String? You can use ‘in’ keyword to check the existence of a sub-string in a string. Example-1 "pass" in

    Read More

  • SQL – How To Alter SQL Table?

    SQL – How To Alter SQL Table?

    SQL – How To Alter SQL Table? Table Of Contents: What Is Altering A Table? Syntax Of Altering A Table. Examples Of Altering A Table. (1) What Is Altering A Table? The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table. (2) Syntax Of Altering A Table? Adding A Column: ALTER TABLE table_name ADD column_name datatype; Dropping A Column: ALTER TABLE table_name DROP COLUMN column_name; Renaming A Column: ALTER TABLE table_name RENAME COLUMN old_name to new_name; Modifying Datatype Of A Column:

    Read More

  • SQL – How To Drop SQL Table?

    SQL – How To Drop SQL Table?

    SQL – How To Drop SQL Table? Table Of Content: What Is Dropping A Table? Syntax Of Dropping SQL Table. Examples Of Dropping SQL Table. (1) What Is Dropping A Table? Dropping a table means, deleting the entire table from the database. Be careful before dropping a table. Deleting a table will result in the loss of complete information stored in the table! (2) Syntax Of Dropping SQL Table. DROP TABLE table_name; (3) Examples Of Dropping SQL Table. DROP TABLE Shippers;

    Read More

  • SQL – How To Create A Table?

    SQL – How To Create A Table?

    SQL – How To Create A Table? Table Of Contents: Syntax Of Creating A Table. Examples Of Creating A Table. (1) Syntax Of Creating A Table CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, …. ); (2) Examples Of Creating A Table Example-1: Creating A New Table CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); Example-2: Create Table Using Another Table CREATE TABLE TestTable AS SELECT customername, contactname FROM customers;

    Read More

  • SQL – How To Backup A DataBase?

    SQL – How To Backup A DataBase?

    SQL – How To Backup A DataBase? Table Of Content: Syntax Of Database Backup. Examples Of Database Backup. (1) Syntax Of Database Backup. BACKUP DATABASE databasename TO DISK = ‘filepath’; The SQL BACKUP WITH DIFFERENTIAL Statement BACKUP DATABASE databasename TO DISK = ‘filepath’ WITH DIFFERENTIAL; (2) Examples Of Database Backup. Example-1: BACKUP DATABASE Example BACKUP DATABASE testDB TO DISK = ‘D:backupstestDB.bak’; Example-2: BACKUP WITH DIFFERENTIAL Example BACKUP DATABASE testDB TO DISK = ‘D:backupstestDB.bak’ WITH DIFFERENTIAL;

    Read More