Python Values - Variables
Python Values - Variables
s = 'a\tb\nA\tB’ rs = r'a\tb\nA\tB’
print(s) print(rs)
Assignment statement:
x = 10 “x is assigned the value
print(x) x = 10
10,” print('x = ' + str(x))
x = 20
print('x = ' + str(x))
Assignment operator x = 30
print('x =', x)
x = 10
x = 20
comma-separated list
x = 30
Formatting string
print('{0} {1}'.format(0, 10**0)) 0 1 1 0
print('{0} {1}'.format(1, 10**1)) 1 10 10 1
print('{0} {1}'.format(2, 10**2)) 2 100 100 2
print('{0} {1}'.format(3, 10**3)) 3 1000 1000 3
print('{0} {1}'.format(4, 10**4)) 4 10000 10000 4
import heapq
nums = [1, 8, 2, 23, 7, -4, 18, 23, 42, 37, 2]
print(heapq.nlargest(3, nums)) # Prints [42, 37, 23]
print(heapq.nsmallest(3, nums)) # Prints [-4, 1, 2]