-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringFORMATTING.py
More file actions
47 lines (29 loc) · 914 Bytes
/
stringFORMATTING.py
File metadata and controls
47 lines (29 loc) · 914 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
# # F-string
# x=16
# print(f'the value of x is : {x}')
# # display the price with 2 decimals.
# price = 100
# print(f"The price is {price:.2f} dolloars")
# # Perform operation in F-Strings .
# txt = f"The price is {20*100} dollars"
# print(txt)
# # add taxes before math operations on variables:
# price = 100
# tax = 0.25
# txt = f"the price is {price+(price*tax)} dollars"
# print(txt)
# print(f"The Price is {price+(price*tax)} dollars")
# # if....else statements inside the placeholders
# price = 99
# txt = f"It is {'Expensive' if price >90 else 'cheap'}"
# print(txt)
# print(f"It is very {'Expensive' if price >80 else 'cheap'}")
# # Execute Functions in F-String
# fruit = "apples"
# txt = f"I love {fruit.upper()}"
# print(txt)
# print(f"I love {fruit.upper()}")
# def my_fun(x):
# return x * 0.3048
# txt = f"The plane is flying at a {my_fun(30000)} meter altitude"
# print(txt)