-
Notifications
You must be signed in to change notification settings - Fork 0
/
26-string-format.py
32 lines (24 loc) · 1.03 KB
/
26-string-format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#str.format() = optional method that gives users
# more control when displaying output
animal = "cow"
item = "moon"
print("the "+animal+" jumped over the "+item)
print("the {} jumped over the {}".format(animal,item))
print("the {1} jumped over the {0}".format(animal,item)) #position argument
print("the {animal} jumped over the {item}".format(animal="bimbim",item="bambam"))
text = "the {} jumped over the {}"
print(text.format(animal,item))
name="amine"
print("Hello, my name is {}".format(name))
print("hello, my name is {:<10}. nice to meet you".format(name))
print("hello, my name is {:>10}. nice to meet you".format(name))
print("hello, my name is {:^10}. nice to meet you".format(name))
number= 3.14159
print("the number pi is {:.2f}".format(number))
num = 1000
print("the number pi is {:,}".format(num))
print("the number pi is {:b}".format(num))
print("the number pi is {:o}".format(num))
print("the number pi is {:x}".format(num))
print("the number pi is {:X}".format(num))
print("the number pi is {:e}".format(num))