- Trending Categories
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
Found 34487 Articles for Programming
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
1K+ Views
Class variables vs Instance VariablesAll variables outside the class __init__ function in Python are class variables while those inside the same are instance variables. The difference between the class variables and instance variables is understood better by examining the code belowExampleclass MyClass: stat_elem = 456 def __init__(self): self.object_elem = 789 c1 = MyClass() c2 = MyClass() # Initial values of both elements >>> print c1.stat_elem, c1.object_elem 456 789 >>> print c2.stat_elem, c2.object_elem 456 789 # Let's try changing the static element MyClass.static_elem = 888 >>> print c1.stat_elem, c1.object_elem 888 789 >>> print ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
127 Views
Class variables are variables that are declared outside the__init__method. These are static elements, meaning, they belong to the class rather than to the class instances. These class variables are shared by all instances of that class. Example code for class variables Exampleclass MyClass: __item1 = 123 __item2 = "abc" def __init__(self): #pass or something elseYou'll understand more clearly with more code −class MyClass: stat_elem = 456 def __init__(self): self.object_elem = 789 c1 = MyClass() c2 = MyClass() # Initial values of both elements >>> print c1.stat_elem, c1.object_elem 456 ... Read More
![Vikram Chiluka](https://www.tutorialspoint.com/assets/profiles/495654/profile/60_4081994-1659334126.jpg)
4K+ Views
In this article, we will show you how to declare an attribute in python without a value. In Python, as well as in several other languages, there is a value that means "no value". In Python, that value with no value is None, let us see how it is used. You simply cannot. Variables are just names in Python. A name always refers to an object ("is bound"). It is conventional to set names that do not yet have a meaningful value but should be present to None. Method 1: By Initializing them with None Directly We can directly assign ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
7K+ Views
selfThe word 'self' is used to represent the instance of a class. By using the "self" keyword we access the attributes and methods of the class in python.__init__ method"__init__" is a reseved method in python classes. It is called as a constructor in object oriented terminology. This method is called when an object is created from a class and it allows the class to initialize the attributes of the class.ExampleFind out the cost of a rectangular field with breadth(b=120), length(l=160). It costs x (2000) rupees per 1 square unitclass Rectangle: def __init__(self, length, breadth, unit_cost=0): self.length ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
721 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
![Janani Jaganathan](https://www.tutorialspoint.com/assets/profiles/506990/profile/60_3923617-1661405985.jpg)
2K+ Views
Execution Engine in Java is the core component of the JVM (java virtual machine) which communicates with different memory areas of the JVM. This component is used to execute the bytecode that is assigned to the runtime data areas via the classloader. In addition to this, each java Class file is executed through the execution engine, and each thread that is present in a running application is a distinct instance of the virtual machine’s execution engine. Hence, by reading this article, you will understand the execution engine in more detail, but before that, let’s comprehend what Java Virtual Machine is. ... Read More
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
415 Views
In this article, we will show how to sort a list of dictionaries by the values of the dictionary in Python. Sorting has always been a useful technique in everyday programming. Python's dictionary is often used in a wide range of applications, from competitive to developer-oriented (example-handling JSON data). It can be useful in certain situations to be able to filter dictionaries based on their values. Below are the 2 methods to accomplish this task − Using sorted() and itemgetter Using sorted() and lambda functions What is a Dictionary? Dictionaries are Python's version of an associative array data ... Read More
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
2K+ Views
The slice operator in Python takes two operands. First operand is the beginning of slice. The index is counted from left by default. A negative operand starts counting from end. Second operand is the index of last character in slice. If omitted, slice goes upto end.We want last four characters. Hence we count beginning of position from end by -4 and if we omit second operand, it will go to end.>>> string = "Thanks. I am fine" >>> string[-4:] 'fine'
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
3K+ Views
The following code using Python regex matches the given multiple words in the given stringExampleimport re s = "These are roses and lilies and orchids, but not marigolds or .." r = re.compile(r'\broses\b | \bmarigolds\b | \borchids\b', flags=re.I | re.X) print r.findall(s)OutputThis gives the output['roses', 'orchids', 'marigolds']
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
488 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