AmitDiwan has Published 10744 Articles

Kotlin Program to Swap Two Numbers

AmitDiwan

AmitDiwan

Updated on 13-Oct-2022 12:26:30

1K+ Views

In this article, we will understand how to how to swap two numbers in Kotlin. This is done using a temporary variable. Below is a demonstration of the same Suppose our input is val1 : 45 val2 : 60 The desired output would be val1 : 60 val2 : ... Read More

Kotlin Program to Add two Numbers

AmitDiwan

AmitDiwan

Updated on 13-Oct-2022 12:24:26

5K+ Views

In this article, we will understand how to add two numbers. This can be done using the ‘+’ operator. Below is a demonstration of the same Suppose our input is input1 : 10 input2 : 15 The desired output would be Sum : 25 Algorithm Step 1 − ... Read More

Kotlin Program to Print a String

AmitDiwan

AmitDiwan

Updated on 13-Oct-2022 12:22:15

646 Views

In this article, we will understand how to print a string. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). Below is a demonstration of the same Suppose our input is − Hello my name is John! The desired output would ... Read More

Kotlin Program to Print an Integer

AmitDiwan

AmitDiwan

Updated on 13-Oct-2022 12:19:29

657 Views

In this article, we will understand how to print an integer. Integer is a primitive data type that contains numbers up to 32 bits. Below is a demonstration of the same − Suppose our input is − 45 The desired output would be − The integer is: 45 ... Read More

Hello World program in Kotlin

AmitDiwan

AmitDiwan

Updated on 13-Oct-2022 12:15:46

504 Views

In this article, we will understand how to print hello world in Kotlin. Hello world is stored as a string format and is printed using ‘print()’ function. Input Suppose our input is Hello World Output The expected out should be Hello World Algorithm Step 1 − START ... Read More

How do I access the serial (RS232) port in Python?

AmitDiwan

AmitDiwan

Updated on 20-Sep-2022 11:56:47

23K+ Views

To access the serial port in Python, use the pyserial module, which Python Serial Port Extension for Win32, OSX, Linux, BSD, Jython, IronPython. Let us see the features - Access to the port settings through Python properties. Support for different byte sizes, stop bits, parity and flow control with ... Read More

How do I find the current module name in Python?

AmitDiwan

AmitDiwan

Updated on 20-Sep-2022 11:24:17

13K+ Views

A module can find out its own module name by looking at the predefined global variable __name__. If this has the value '__main__', the program is running as a script. Example def main(): print('Testing…...') ... if __name__ == '__main__': main() ... Read More

How do I parcel out work among a bunch of worker threads in Python?

AmitDiwan

AmitDiwan

Updated on 20-Sep-2022 11:18:19

180 Views

To parcel out work among a bunch of worker threads, use the concurrent.futures module, especially the ThreadPoolExecutor class. With that an alternative, if you want fine control over the dispatching algorithm, you can write your own logic manually. Use the queue module to create a queue containing a list of ... Read More

How do you implement persistent objects in Python?

AmitDiwan

AmitDiwan

Updated on 20-Sep-2022 11:17:02

973 Views

To implement persistent objects in Python, use the following libraries. shelve pickle The shelve module A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle ... Read More

How do I create documentation from doc strings in Python?

AmitDiwan

AmitDiwan

Updated on 20-Sep-2022 11:15:24

777 Views

To create documentation from doc strings, we can use the following packages and modules − Pydoc Epydoc Sphinx Let us understand them one by one − Pydoc The pydoc module can create HTML from the doc strings in your Python source code. The pydoc module automatically generates documentation ... Read More

Advertisements