Python

Int

a = 100
b = 7
*# Divide 100 by 7.*
print(a / b)
*# Discard fractional part of result.*
print(a // b)14.285714285714286
14

Convert

number = 100
*# Convert this number to a binary string.*
result = **bin**(number)
print(result)0b1100100bin(-1) -0b1
bin(0) 0b0

import time
a = 1000
b = 223
c = 0
print (time.time())
*# Version 1: normal division*
i = 0
while i < 10000000:
c = a / b
i += 1
print (time.time())
*# Version 2: integer result division*
i = 0
while i < 10000000:
c = a // b
i += 1
print (time.time())1345843075.764
1345843077.922 (/ = 2.158 s)
1345843080.448 (// = 2.526 s)

Divmod

Random

pow

bool

Prime Number

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Apr 16, 2023 (edit).