Create Instance Objects Using __init__ in Python

Rajendra Dharmkar
Updated on 13-Jun-2020 08:29:40

882 Views

The instantiation or calling-a-class-object operation creates an empty object. Many classes like to create objects with instances with a specific initial state. Therefore a class may define a special method named __init__(), as follows −def __init__(self) −    self.data = [ ]When a class defines an __init__() method, class instantiation automatically invokes the newly-created class instance which is obtained by −x = MyClass()The __init__() method may have arguments. In such a case, arguments given to the class instantiation operator are passed on to __init__(). For example, >>> class Complex: ...     def __init__(self, realpart, imagpart): ...       ... Read More

Check if a Variable Exists in JavaScript

Amit Sharma
Updated on 13-Jun-2020 08:28:18

537 Views

To check if a variable exists in JavaScript, you need to check it against null as in the following code. Here, we’re checking the existence of variable myVar −                    var myVar = 20;          if(myVar !== undefined && myVar !== null) {             document.write("Variable exists");          }          

Use of Declaring Variables in JavaScript

Ali
Ali
Updated on 13-Jun-2020 08:27:46

198 Views

Before you use a variable in a JavaScript program, you must declare it. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.Variables are declared with the var keyword as follows.     You can also declare multiple variables with the same var keyword as follows −     This is also you can assign values −var rank = 2; var points = 100;

Purpose of new Boolean in JavaScript

Johar Ali
Updated on 13-Jun-2020 08:21:10

320 Views

The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.The new Boolean() is used to create a new object. Use the following syntax to create a boolean object.var val = new Boolean(value);ExampleLet us see an example of toString() method, which returns a string of either "true" or "false" depending upon the value of the object −           JavaScript toString() Method                        var flag = new Boolean(false);          document.write( "flag.toString = " + flag.toString() );          

Addition Operator (+) in JavaScript

Anvi Jain
Updated on 13-Jun-2020 08:19:52

327 Views

The addition operator is used to add two operands.ExampleYou can try to run the following code to work with Addition Operator −                    var a = 33;          var b = 10;          document.write("a + b = ");          result =a + b;          document.write(result);          

Addition Assignment Operator (+=) in JavaScript

Nitya Raut
Updated on 13-Jun-2020 08:19:32

280 Views

It adds the right operand to the left operand and assigns the result to the left operand.ExampleYou can try to run the following code to learn how to work with Addition Assignment Operator −                    var a = 33;          var b = 10;          document.write("Value of a => (a += b) => ");          result = (a += b);          document.write(result);          document.write(linebreak);          

Declare Boolean Variables in JavaScript

Amit Sharma
Updated on 13-Jun-2020 07:49:15

677 Views

A boolean variable in JavaScript has two values True or False.ExampleYou can try to run the following code to learn how to work with Boolean variables −           35 > 20       Click for result                      function myValue() {             document.getElementById("test").innerHTML = Boolean(35 > 20);          }          

Declare Numbers in JavaScript

Ali
Ali
Updated on 13-Jun-2020 07:43:55

5K+ Views

JavaScript is untyped language. This means that a JavaScript variable can hold a value of any data type. To declare variables in JavaScript, you need to use the var keyword. Whether it is a number or string, use the var keyword for declaration.Here’s how you can declare numbers in JavaScript −var points = 100; var rank = 5;ExampleYou can try to run the following code to learn how to declare number in JavaScript −                                

Unsigned Right Shift Operator in JavaScript

Nancy Den
Updated on 13-Jun-2020 07:41:03

583 Views

This operator is just like the >>operator, except that the bits shifted in on the left are always zero i.e. xeroes are filled in from the left.ExampleYou can try to run the following code to learn how to work with unsigned right shift operator −                    var a =-14;          var b =2; // Shift right two bits          document.write("(a >>> b) => ");          result =(a >>> b);          document.write(result);          

Validate a URL with Regular Expression in Python

Rajendra Dharmkar
Updated on 13-Jun-2020 07:28:42

672 Views

There's no validate method as almost anything is a valid URL. There are some punctuation rules for splitting it up. Without any punctuation, you still have a valid URL.Depending on the situation, we use following methods.If you trust the data, and just want to verify if the protocol is HTTP, then urlparse is perfect.If you want to make the URL is actually a true URL, use the cumbersome and maniacal regexIf you want to make sure it's a real web address, use the following codeExampleimport urllib try:     urllib.urlopen(url) except IOError:     print "Not a real URL"Read More

Advertisements