Help Function in Python

Pradeep Elance
Updated on 23-Aug-2019 12:31:41

248 Views

Many times we need to look into the python documentation for some help on functions, modules etc. Python provides a help function that gives us this needed results.SyntaxHelp(‘term’) Where term is the word on which we want the help.ExampleIn the below example we seek to find help on the word time. The output comes from python documentation and it is quite exhaustive. Live Demoprint(help('time'))OutputRunning the above code gives us the following result −Help on built-in module time: NAME time - This module provides various functions to manipulate time values. DESCRIPTION There are two standard representations of time. One is the ... Read More

Extract From Datetime Column in MySQL Ignoring Whitespace

AmitDiwan
Updated on 23-Aug-2019 12:30:25

209 Views

To extract from datetime column, you can use date() along with trim(). Here, trim() is used to remove whitespace while comparing. Let us first create a table −mysql> create table DemoTable661(Duedate datetime); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable661 values(' 2019-01-21 12:02:21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable661 values(' 2019-07-11 11:55:59 '); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable661 values('2019-11-21 04:00:59 '); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select ... Read More

Filter in Python

Pradeep Elance
Updated on 23-Aug-2019 12:29:22

635 Views

We sometimes arrive at a situation where we have two lists and we want to check whether each item from the smaller list is present in the bigger list or not. In such case we use the filter() function as discussed below.SyntaxFilter(function_name, sequence name)Here Function_name is the name of the function which has the filter criteria. Sequence name is the sequence which has elements that needs to be filtered. It can be sets, lists, tuples, or other iterators.ExampleIn the below example we take a bigger list of some month names and then filter out those months which does not have ... Read More

Subtract Number of Days from a Date in MySQL

AmitDiwan
Updated on 23-Aug-2019 12:27:37

317 Views

Yes, you can use date_sub() to subtract number of days from a date. Following is the syntax −select date_sub(yourColumnName, Interval yourAmountOfDays day) from yourTableName;Let us first create a table −mysql> create table DemoTable660(AdmissionDate datetime); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable660 values('2018-01-24'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable660 values('2019-07-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable660 values('2020-11-20'); Query OK, 1 row affected (0.59 sec)Display all records from the table using select statement −mysql> select *from DemoTable660;This will produce the ... Read More

Factorial in Python

Pradeep Elance
Updated on 23-Aug-2019 12:26:17

6K+ Views

Finding the factorial of a number is a frequent requirement in data analysis and other mathematical analysis involving python. The factorial is always found for a positive integer by multiplying all the integers starting from 1 till the given number. There can be three approaches to find this as shown below.Using a For LoopWe can use a for loop to iterate through number 1 till the designated number and keep multiplying at each step. In the below program we ask the user to enter the number and convert the input to an integer before using it in the loop. This ... Read More

Mathematical Logical Terms and Definitions

Mahesh Parahar
Updated on 23-Aug-2019 12:22:36

1K+ Views

TautologiesA Tautology is a formula which is always true for every value of its propositional variables.Example − Prove [ (A → B) ∧ A ] → B is a tautologyThe truth table is as follows −ABA → B(A → B) ∧ A[ (A → B) ∧ A ] → BTrueTrueTrueTrueTrueTrueFalseFalseFalseTrueFalseTrueTrueFalseTrueFalseFalseTrueFalseTrueAs we can see every value of [ (A → B) ∧ A ] → B is "True", it is a tautology.ContradictionsA Contradiction is a formula which is always false for every value of its propositional variables.Example − Prove (A ∨ B) ∧ [ ( ¬ A) ∧ (¬ B) ] ... Read More

Fetch Specific Row When Values Are the Same in MySQL

AmitDiwan
Updated on 23-Aug-2019 12:19:22

71 Views

To fetch a specific row when values are the same, use GROUP BY. Let us first create a table −mysql> create table DemoTable659(Id int, Name varchar(100), Score int); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable659 values(11, 'John', 45); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable659 values(15, 'John', 59); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable659 values(15, 'Sam', 61); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable659;This will produce the ... Read More

Mathematical Logical Connectives

Mahesh Parahar
Updated on 23-Aug-2019 12:17:35

18K+ Views

A Logical Connective is a symbol which is used to connect two or more propositional or predicate logics in such a manner that resultant logic depends only on the input logics and the meaning of the connective used.Generally there are five connectives which are −OR (∨)AND (∧)Negation/ NOT (¬)Implication / if-then (→)If and only if (⇔).OR (∨) − The OR operation of two propositions A and B (written as A ∨ B) is true if at least any of the propositional variable A or B is true.The truth table is as follows −ABA ∨ BTrueTrueTrueTrueFalseTrueFalseTrueTrueFalseFalseFalseAND (∧) − The AND operation ... Read More

Execute Python Code Online

Pradeep Elance
Updated on 23-Aug-2019 12:15:41

1K+ Views

Exec function can dynamically execute code of python programs. The code can be passed in as string or object code to this function. The object code is executed as is while the string is first parsed and checked for any syntax error. If no syntax error, then the parsed string is executed as a python statement.Syntax for exec() Functionexec(object, globals, locals)WhereObject − A string or a code object passed onto the method.globals − A dictionary of available global methods and variables.locals − A dictionary of available local methods and variables.Passing StringIn the below example we pass a single line of ... Read More

Matching Graph

Mahesh Parahar
Updated on 23-Aug-2019 12:10:27

440 Views

A matching graph is a subgraph of a graph where there are no edges adjacent to each other. Simply, there should not be any common vertex between any two edges.MatchingLet 'G' = (V, E) be a graph. A subgraph is called a matching M(G), if each vertex of G is incident with at most one edge in M, i.e., deg(V) ≤ 1 ∀ V ∈ Gwhich means in the matching graph M(G), the vertices should have a degree of 1 or 0, where the edges should be incident from the graph G.Notation − M(G)ExampleIn a matching, if deg(V) = 1, ... Read More

Advertisements