- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
You can use the "from module import function" statement to import a specific function from a Python module. For example, if you want to import the sin function from the math library without importing any other function, you can do it as follows:>>> from math import sin >>> sin(0) 0.0Note that you don't have to prefix sin with "math." as only sin has been imported and not math. Also you can alias imported functions. For example,>>> from math import cos as cosine >>> cosine(0) 1.0
For this, you can use the CASE statement along with SUM(). Here, we will be finding the count of Male and Female records from a column with employee gender values. Let us first create a table −mysql> create table DemoTable ( EmployeeGender ENUM('Male', 'Female') ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Male'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Female'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Male'); Query OK, 1 row affected (0.10 sec) mysql> insert into ... Read More
The @ symbol in a stored procedure can be used for user-defined session variables. Let us first create a table −mysql> create table DemoTable ( StudentName varchar(50) ); Query OK, 0 rows affected (1.30 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (1.00 sec) mysql> insert into DemoTable values('John Doe'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.53 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More
This problem can be solved by reversing the string, reversing the string to be replaced, replacing the string with reverse of string to be replaced with and finally reversing the string to get the result. You can reverse strings by simple slicing notation - [::-1]. To replace the string you can use str.replace(old, new, count). For example, def rreplace(s, old, new): return (s[::-1].replace(old[::-1], new[::-1], 1))[::-1] rreplace('Helloworld, hello world, hello world', 'hello', 'hi') This will give the output:'Hello world, hello world, hi world'Another method by which you can do this is to reverse split the string once on the old string ... Read More
Let us first create a table −mysql> create table DemoTable ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('John', 'Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris', 'Brown'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('Robert', 'Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert ... Read More
This type of sort in which you want to sort on the basis of numbers within string is called natural sort or human sort. For example, if you have the text:['Hello1', 'Hello12', 'Hello29', 'Hello2', 'Hello17', 'Hello25'] Then you want the sorted list to be:['Hello1', 'Hello2', 'Hello12', 'Hello17', 'Hello25', 'Hello29'] and not:['Hello1', 'Hello12', 'Hello17', 'Hello2', 'Hello25', 'Hello29'] To do this we can use the extra parameter that sort() uses. This is a function that is called to calculate the key from the entry in the list. We use regex to extract the number from the string and sort on both text and number. import re ... Read More
There are two ways to go about replacing \ with \ or unescaping backslash escaped strings in Python. First is using literal_eval to evaluate the string. Note that in this method you need to surround the string in another layer of quotes. For example:>>> import ast >>> a = '"Hello,world"' >>> print ast.literal_eval(a) Hello, worldAnother way is to use the decode('string_escape') method from the string class. For example,>>> print "Hello,world".decode('string_escape') Hello, world
For this, you can use the property IS NULL for null values in MySQL. Let us first create a table −mysql> create table DemoTable ( Name varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(null); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(null); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 ... Read More
Let us first create a table −mysql> create table DemoTable ( Id int, ColorName varchar(100) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Red'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(101, 'Green'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(101, 'Blue'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(102, 'Yellow'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(100, 'Purple'); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More
Let us first create a table. Here, we have VARCHAR type for value −mysql> create table DemoTable ( Value varchar(100) ); Query OK, 0 rows affected (1.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('100'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('1244'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('15789'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------+ | Value | +-------+ | 100 | ... Read More
To Continue Learning Please Login
Login with Google