# Formatting In String
'''
# Case- 1: Basic Formatting for default, positional and keyword arguments
name='Aakash'
salary=10000
age=28
# format() is a method of <str> class
print(name,"'s salary is ",salary," and his age is ",age)
print( "{}'s salary is {} and his age is {}".format(name,salary,age) )
print( "{0} 's salary is {1} and his age is {2}".format(name,salary,age) )
print( "{1} 's salary is {2} and his age is {0}".format(name,salary,age) )
print( "{x} 's salary is {y} and his age is {z}".format(z=age,y=salary,x=name) )
print( "{x} 's salary is {y} and his age is {z}".format(z=age,x=name,y=salary) )
'''
'''
Output:
Aakash 's salary is 10000 and his age is 28
Aakash 's salary is 10000 and his age is 28
Aakash 's salary is 10000 and his age is 48
'''
'''
# Case-2: Formatting Numbers
d #Decimal IntEger
f #Fixed point number(float). The default scale is 6
b #Binary format
o #Octal Format
x #Hexa Decimal Format(Lower case)
X #Hexa Decimal Format(Upper case)
'''
'''
# Eg-1:
print("The intEger number is: {}".format(123))
print("The intEger number is: {:d}".format(123))
print("The intEger number is: {:5d}".format(123))
print("The intEger number is: {:05d}".format(123))
print("The intEger number is: {:05d}".format(123456789))
'''
'''
Output:
The intEger number is: 123
The intEger number is: 123
The intEger number is: 123
The intEger number is: 00123
'''
'''
# Eg-2:
print( "The float number is: {}".format(123.4567) )
print( "The float number is: {:f}".format(123.4567) ) #print 6 scale value
print( "The float number is: {:8.3f}".format(123.4567) )
print( "The float number is: {:8.3f}".format(123.4567) )
print( "The float number is: {:08.3f}".format(123.4567) )
print( "The float number is: {:08.3f}".format(123.45) )
print( "The float number is: {:08.3f}".format(786786123.45) )
'''
'''
Output:
The float number is: 123.4567
The float number is: 123.456700
The float number is: 123.457
The float number is: 0123.457
The float number is: 0123.450
The float number is: 786786123.450
Note:
{:5d}
• It takes an intEger argument and assigns a minimum width of 5.
{:8.3f}
• It takes a float argument and assigns a minimum width of 8 including "." and
after decimal point exactly 3 digits are allowed with round operation if required
{:05d}
• The blank places can be filled with 0. In this place only 0 allowed.
{:08.3f}
• Total positions should be minimum 8.
• After decimal point exactly 3 digits are allowed. If it is less then 0s will
be placed in the last positions
• If total number is < 8 positions then 0 will be placed in starting position
• If total number is >8 positions then all intEgral digits will be considered.
• The extra digits we can take only 0
Note: For numbers default alignment is Right Alignment(>)
'''
'''
# Eg-3: Print Decimal value in binary, octal and hexadecimal form
print( "Binary Form:{0:b}".format(153) )
print( "Octal Form:{0:o}".format(153) )
print( "Hexa decimal Form:{0:x}".format(154) )
print( "Hexa decimal Form:{0:X}".format(154) )
'''
'''
Output:
Binary Form:10011001
Octal Form:231
Hexa decimal Form:9a
Hexa decimal Form:9A
'''
'''
Case-3: Number formatting for signed numbers
While displaying positive numbers,if we want to include + then we have to write
{:+d} and {:+f} Using plus for -ve numbers there is no use and for -ve numbers -
sign will come automatically.
'''
'''
print( "int value with sign:{:+d}".format(123) )
print( "int value with sign:{:+d}".format(-123) )
print( "float value with sign:{:+f}".format(123.456) )
print( "float value with sign:{:+f}".format(-123.456) )
'''
'''
Output:
int value with sign:+123
int value with sign:-123
float value with sign:+123.456000
float value with sign:-123.456000
'''
'''
Case-4: Number formatting with alignment
< , > , ^ and = are used for alignment
< Left Alignment to the remaining space
^ Center alignment to the remaining space
> Right alignment to the remaining space
= Forces the signed(+) (-) to the left most position
'''
'''
# Note: Default Alignment for numbers is Right Alignment.
print( "{:5d}".format(12) )
print( "{:<5d}".format(12) )
print( "{:<05d}".format(12) )
print( "{:>5d}".format(12) )
print( "{:>05d}".format(12) )
print( "{:^5d}".format(12) )
print( "{:=5d}".format(-12) )
print( "{:^10.3f}".format(12.23456) )
print( "{:=12.3f}".format(-12.23456) )
'''
'''
O/P
12
12
12000
12
00012
12
- 12
12.235
- 12.235
'''
'''
Case-5: String formatting with format()
Similar to numbers, we can format String values also with format() method.
s.format(string)
'''
'''
# Eg:
print( "{:5d}".format(12) )
print( "{:5}".format("rat") ) # by default left allignment
print( "{:>5}".format("rat") ) # right allignment
print( "{:<5}".format("rat") ) # left allignment
print( "{:^5}".format("rat") ) # centre allignment
print( "{:*^5}".format("rat") )# centre allignment with '*'
print( "{:*^5}".format("Aim Point") )# centre allignment with '*'
print( "{:*^15}".format("Aim Point") )# centre allignment with '*'
'''
'''
O/P
12
rat
rat
rat
rat
*rat*
Aim Point
***Aim Point***
'''
'''
# Case-7: Formatting Date values
import datetime # import 'datetime' module
date = datetime.datetime.now()
# now() is a fn of 'datetime' class & this class is defined
# in 'datetime' module
#print(type(date))
print( "It's now:{:%d/%m/%y %H:%M:%S}".format(date) )
print( "It's now:{:%d/%m/%Y %H:%M:%S}".format(date) )
print( "Todays Date:{:%D}".format(date) )
print( "This Year :{:%Y}".format(date) )
'''
'''
Output
It's now:30/08/20 00:25:39
Todays Date:08/30/20
This Year :2020
'''