Found 34489 Articles for Programming

JSON Formatting in Python

Samual Sam
Updated on 26-Jun-2020 12:26:45

8K+ Views

The JSON (Java Script Object Notation) is light weight, well accepted data interchange format. Using JSON formatting techniques in Python, we can convert JSON strings to Python objects, and also convert Python Objects to JSON strings.To use these functionalities, we need to use the json module of Python. The json module comes with the Python standard library. So at first we have to import it first.import jsonConverting Python objects to JSON StringIn the json module, there are some methods like dump(), and dumps() to convert Python objects to JSON strings. The dump() method takes two arguments, the first one is ... Read More

Type Conversion in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

1K+ Views

Using Python, we can easily convert data into different types. There are different functions for Type Conversion. We can convert string type objects to numeric values, perform conversion between different container types etc. In this section we will see how the conversions can be done using Python. Converting String to Numeric Types To convert from String type objects to Numeric Objects, there are different methods like int(), float() etc. Using the int() method we can convert any number as string to integer value (base 10). It takes the string type argument, default base is 10, We can also specify the ... Read More

Operator Functions in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

646 Views

In Python there are some additional standard library methods for mathematical operations, like arithmetic, logical, relational, bitwise etc. operations. These methods can be found under the operator module. To use it at first we need to import it the operator standard library module. import operator In this section we will see some operator functions for bitwise operations and container operations. Arithmetic Operations At first we will see the arithmetic operating functions. These are like below. Sr.No Functions & Description 1 add(x, y) The add() method is used to add two numbers x and y. ... Read More

Merge two sorted arrays in Python using heapq?

Samual Sam
Updated on 26-Jun-2020 12:19:06

420 Views

In this section we will see how two sorted lists can be merged using the heapq module in Python. As an example, if list1 = [10, 20, 30, 40] and list2 = [100, 200, 300, 400, 500], then after merging it will return list3 = [10, 20, 30, 40, 100, 200, 300, 400, 500]To perform this task, we will use the heapq module. This module comes with Python as Standard Library Module. So we need to import it before using it.import heapqThe heapq module has some properties. These are like below −Method heapq.heapify(iterable)It is used to convert an iterable dataset ... Read More

Creating child process using fork() in Python

karthikeya Boyini
Updated on 26-Jun-2020 12:19:41

2K+ Views

Our task is to create a child process and display process id of both parent and child process using fork() function in Python.When we use fork(), it creates a copy of itself, it is a very important aspect of LINUX, UNIX. fork() is mainly applicable for multithreading environment that means the execution of the thread is duplicated created a child thread from a parent thread. When there is an error, the method will return a negative value and for the child process, it returns 0, Otherwise, it returns positive value that means we are in the parent process.The fork() module ... Read More

Determine if a String is a legal Java Identifier

karthikeya Boyini
Updated on 26-Jun-2020 12:20:41

694 Views

To determine if a String is a legal Java Identifier, use the Character.isJavaIdentifierPart() and Character.isJavaIdentifierStart() methods.Character.isJavaIdentifierPart()The java.lang.Character.isJavaIdentifierPart() determines if the character (Unicode code point) may be part of a Java identifier as other than the first character.A character may be part of a Java identifier if any of the following are true.it is a letterit is a currency symbol (such as '$')it is a connecting punctuation character (such as '_')it is a digitit is a numeric letter (such as a Roman numeral character)Character.isJavaIdentifierStart()The java.lang.Character.isJavaIdentifierStart() determines if the character (Unicode code point) is permissible as the first character in a Java ... Read More

Java Program to compare two Java char Arrays

Samual Sam
Updated on 26-Jun-2020 12:21:12

273 Views

To compare two Java char arrays, use the Arrays.equals() method.Let us first declare and initialize some char arrays.char[] arr1 = new char[] { 'p', 'q', 'r' }; char[] arr2 = new char[] { 'p', 'r', 's' }; char[] arr3 = new char[] { 'p', 'q', 'r' };Now let us compare any two of the above arrays.Arrays.equals(arr1, arr2));In the same way, work it for other arrays and compare them.The following is an example.Example Live Demoimport java.util.*; public class Demo {    public static void main(String []args) {       char[] arr1 = new char[] { 'p', 'q', 'r' };     ... Read More

Convert string to char array in Java

karthikeya Boyini
Updated on 26-Jun-2020 12:21:40

3K+ Views

The following is our string.String str = "Tutorial";Now, use the toCharArray() method to convert string to char array.char[] ch = str.toCharArray();Now let us see the complete example.Example Live Demopublic class Demo {    public static void main(String []args) {       String str = "Tutorial";       System.out.println("String: "+str);       char[] ch = str.toCharArray();       System.out.println("Character Array...");       for (int i = 0; i < ch.length; i++) {          System.out.print(ch[i]+" ");       }    } }OutputString: Tutorial Character Array... T u t o r i a l

Java Program to determine a Character's Unicode Block

Samual Sam
Updated on 26-Jun-2020 12:10:26

315 Views

To determine a Character’s Unicode Block, use the Character.UnicodeBlock.of() method in Java. The method returns the object representing the Unicode block containing the given character, or null if the character is not a member of a defined block.Let us see the syntax of Character.UnicodeBlock.of() method.Character.UnicodeBlock of(char c)Here, c is the character.The following is an example that shows how we can represent the Unicode block containing the given character.Example Live Demopublic class Demo {    public static void main(String []args) {       char ch = '\u5639';       System.out.println(ch);       Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);       ... Read More

Store unicode in a char variable in Java

karthikeya Boyini
Updated on 26-Jun-2020 12:10:49

1K+ Views

To store Unicode in a char variable, simply create a char variable.char c;Now assign unicode.char c = '\u00AB';The following is the complete example that shows what will get displayed: when Unicode is stored in a char variable and displayed.Example Live Demopublic class Demo {    public static void main(String []args) {       int a = 79;       System.out.println(a);       char b = (char) a;       System.out.println(b);       char c = '\u00AB';       System.out.println(c);    } }Output79 O «

Advertisements