Colab

"the quick brown fox jumped over the lazy dog".find("quick")

4
age = 30
height = 180
name = "ben"
score =85

"hi {}, happy {} birthday, your height is {}, your score is {}".format(name, age, height, score)

'hi ben, happy 30 birthday, your height is 180, your score is 85'
age = 30
height = 180
name = "ben"
score =85

"hi {2}, happy {0} birthday, your height is {1}, your score is {3}".format(age, height, name, score)

'hi ben, happy 30 birthday, your height is 180, your score is 85'
x= """hi {0}, 
{0} is a nice name
goodbye {0}
""".format(name, "this is not used")
print(x)

hi ben, 
ben is a nice name
goodbye ben

"{}".format(10/3)

'3.3333333333333335'
import math
math.sin(math.pi)

1.2246467991473532e-16
"{:.2f}".format(math.sin(math.pi))

'0.00'
"{:.20f}".format(math.sin(math.pi))

'0.00000000000000012246'
ord(' ')

32
"0x{:x}".format(ord(' '))

'0x20'
"{:.2}".format(math.sin(math.pi))

'1.2e-16'
"""
steak:                150.00 NIS
pita:                   1.50 NIS
shakshuka im thi na:   25.00 NIS
vat%                   17.00 %
vat:                   35.56
total:                222.40 NIS
"""

'\nsteak:                150.00 NIS\npita:                   1.50 NIS\nshakshuka im thi na:   25.00 NIS\nvat%                   17.00 %\nvat:                   35.56\ntotal:                222.40 NIS\n'
print("{:7.2f}".format(1.5))
print("{:7.2f}".format(222.49))
print("{:7.2f}".format(-10))

  +1.50
 222.49
 -10.00
print("{:+7.2f}".format(1.5))
print("{:+7.2f}".format(222.49))
print("{:+7.2f}".format(-10))

  +1.50
+222.49
 -10.00
print("{:^10.2f}".format(1.5))
print("{:^10.2f}".format(222.49))
print("{:^10.2f}".format(-10))

   1.50   
  222.49  
  -10.00  
print("{:-^10.2f}".format(1.5))
print("{:-^10.2f}".format(222.49))
print("{:-^10.2f}".format(-10))

---1.50---
--222.49--
---10.00--
print("{:#x}".format(32))
print("{:#o}".format(32))
print("{:#b}".format(32))
print("{:#d}".format(32))

0x20
0o40
0b100000
32
x= "hi {2}, happy {0} birthday, your height is {1}, your score is {3}".format(age, height, name, score)
print(x)

x = f"hi {name}, happy {age} birthday, your height is {height}, your score is {score}"
print(x)

hi ben, happy 30 birthday, your height is 180, your score is 85
hi ben, happy 30 birthday, your height is 180, your score is 85
print(f"""freedom is the right to say that {1}+{1} = {1+1}""")

freedom is the right to say that 1+1 = 2
print(f"""{"the quick brown fox".upper().replace("FOX", "cat")}""")

THE QUICK BROWN cat