Programming Articles

Page 2531 of 2547

Why python for loops don't default to one iteration for single objects?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 206 Views

Python cannot iterate over an object that is not 'iterable'. The 'for' loop construct in python calls inbuilt functions within the iterable data-type which allow it to extract elements from the iterable.Since non-iterable data-types don't have these methods, there is no way to extract elements from them. And hence for loops ignore them.

Read More

How to generate statistical graphs using Python?

Ankitha Reddy
Ankitha Reddy
Updated on 30-Jul-2019 490 Views

Python has an amazing graph plotting library called matplotlib. It is the most popular graphing and data visualization module for Python. You can start plotting graphs using 3 lines! For example, from matplotlib import pyplot as plt # Plot to canvas plt.plot([1, 2, 3], [4, 5, 1]) #Showing what we plotted plt.show() This will create a simple graph with coordinates (1, 4), (2, 5) and (3, 1). You can Assign labels to the axes using the xlabel and ylabel functions. For example, plt.ylabel('Y axis') plt.xlabel('X axis') And also provide a title using the title ...

Read More

Java is also not pure object-oriented like c++

Pythonista
Pythonista
Updated on 30-Jul-2019 456 Views

the main() method in Java code is itself inside a class. The static keyword lets the main() method which is the entry point of execution without making an object but you need to write a class. In C++, main() is outside the class and writing class it self is not mandatory. Hence, C++ is not a pure object oriented language bu Java is a completely object oriented language.

Read More

How to write string functions in Java?

Pythonista
Pythonista
Updated on 30-Jul-2019 195 Views

1) take a string from the user and check contains atleast one digit or not:Extract character array from string using toCharArray() method. Run a for loop over each character in array and test if it is a digit by static method isDigit() of character classpublic static boolean chkdigit(String str) { char arr[]=str.toCharArray(); for (char ch:arr) { if (Character.isDigit(ch)) { return true; } } return false; }2.) take ...

Read More

How will you explain Python Operator Overloading?

Jayashree
Jayashree
Updated on 30-Jul-2019 313 Views

Every class in Python, whether built-in or user defined is inherited from object class. The object class has a number of properties whose name is preceded and followed by double underscores (__). Each of these properties is a wrapper around a method of same name. Such methods are called special or magic methods.The magic methods __lt__(), __gt__(), __eq__(), __ne__(), etc. are overridden in a class to overload == and != operators respectively.

Read More

What are Java methods equivalent to C# virtual functions?

Sharon Christine
Sharon Christine
Updated on 30-Jul-2019 605 Views

All instance methods in Java are virtual except, static methods and private methods.

Read More

How to execute Python CGI Script on Apache Server?

Arnab Chakraborty
Arnab Chakraborty
Updated on 30-Jul-2019 602 Views

in apache server normally python script will not run. SO you have to go httpd.conf file in apache server, inside that you will find some .php, .asp etc in a property called AddHandler, you have to put there .py. save the file and restart the server. then run your python CGI script, it will run properly 

Read More

How to write Python CGI program to interact with MySQL?

Arnab Chakraborty
Arnab Chakraborty
Updated on 30-Jul-2019 1K+ Views

suppose you want to login into you account using Python CGi script, below is the details login.html email: password: login.py #!C:\Python27\python.exe import MySQLdb import cgi import Cookie # Open database connection db = MySQLdb.connect("localhost", "root", "", "student" ) # prepare a ...

Read More

How to use R in Java-8 regex.

Arnab Chakraborty
Arnab Chakraborty
Updated on 30-Jul-2019 550 Views

\R matches any line break as defined by the Unicode standardPattern p = Pattern.compile("\R");Unicode line-break sequence is equivalent to \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]

Read More

How can I preserve Python tuples with JSON?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 463 Views

There is no concept of a tuple in the JSON format. Python's JSON module converts Python tuples to JSON lists because that's the closest thing in JSON to a tuple. Immutability will not be preserved. If you want to preserve them, use a utility like a pickle or write your own encoders and decoders.If you're using pickle, it won't store the Python temples in JSON files but in pkl files. This isn't useful if you're sending data across the web. The best way is to use your own encoders and decoders that will differentiate between lists and tuples depending on ...

Read More
Showing 25301–25310 of 25,467 articles
Advertisements