Pythonista has Published 42 Articles

How to convert an integer to a unicode character in Python?

Pythonista

Pythonista

Updated on 09-Sep-2023 15:26:00

3K+ Views

Python library's chr() function converts Unicode character associated to any integer which is between 0 an 0x10ffff.>>> chr(36) '$' >>> chr(97) 'a' >>> chr(81) 'Q'

How to save a Python Dictionary to CSV file?

Pythonista

Pythonista

Updated on 24-Aug-2023 16:15:39

38K+ Views

CSV (Comma Separated Values) is a most common file format that is widely supported by many platforms and applications.Use csv module from Python's standard library. Easiest way is to open a csv file in 'w' mode with the help of open() function and write  key value pair in comma separated ... Read More

Why we can't use arrow operator in gets and puts?

Pythonista

Pythonista

Updated on 22-Jun-2020 09:11:02

86 Views

You can't read user input in an un-initialized pointer. Instead, have a variable of the struct data type and assign its address to pointer before accessing its inner elements by → operatorexample#include struct example{    char name[20]; }; main(){    struct example *ptr;    struct example e;    puts("enter ... Read More

Python - How to convert this while loop to for loop?

Pythonista

Pythonista

Updated on 20-Jun-2020 07:41:33

945 Views

Usin count() function in itertools module gives an iterator of evenly spaced values. The function takes two parameters. start is by default 0 and step is by default 1. Using defaults will generate infinite iterator. Use break to terminate loop.import itertools percentNumbers = [ ] finish = "n" num = ... Read More

How to emulate a do-while loop in Python?

Pythonista

Pythonista

Updated on 19-Jun-2020 11:55:40

230 Views

Python doesn't have an equivalent of do-while loop as in C/C++ or Java. The essence of do-while loop is that the looping condition is verified at the end of looping body. This feature can be emulated by following Python code −Examplecondition=True x=0 while condition==True:      x=x+1      print ... Read More

What is vertical bar in Python bitwise assignment operator?

Pythonista

Pythonista

Updated on 02-Mar-2020 09:53:31

932 Views

Vertical bar (|) stands for bitwise or operator. In case of two integer objects, it returns bitwise OR operation of two>>> a=4 >>> bin(a) '0b100' >>> b=5 >>> bin(b) '0b101' >>> a|b 5 >>> c=a|b >>> bin(c) '0b101'

How to implement Python __lt__ __gt__ custom (overloaded) operators?

Pythonista

Pythonista

Updated on 02-Mar-2020 09:52:46

3K+ Views

Python has magic methods to define overloaded behaviour of operators. The comparison operators (=, == and !=) can be overloaded by providing definition to __lt__, __le__, __gt__, __ge__, __eq__ and __ne__ magic methods.  Following program overloads < and > operators to compare objects of distance class. class distance:   def __init__(self, ... Read More

How to overload Python comparison operators?

Pythonista

Pythonista

Updated on 02-Mar-2020 08:17:26

11K+ Views

Python has magic methods to define overloaded behaviour of operators. The comparison operators (=, == and !=) can be overloaded by providing definition to __lt__, __le__, __gt__, __ge__, __eq__ and __ne__ magic methods. Following program overloads == and >= operators to compare objects of distance class.class distance:       def ... Read More

How does Python while loop work?

Pythonista

Pythonista

Updated on 27-Feb-2020 07:09:54

210 Views

while statement is very popular looping statement in many languages including Python. Is general usage is −while expr==True:     stmt1     stmt2     .....The block of statements with increased indent after : symbol will be repeatedly executed as long as expr remains true. Obviously, certain provision must ... Read More

How to use continue statement in Python loop?

Pythonista

Pythonista

Updated on 27-Feb-2020 05:24:32

98 Views

The loop control statement continue abandons the pending statements in current iteration of the looping block and starts next iteration. The continue statement appears in a conditional block inside loopExamplex=0 while x

Advertisements