Untitled Document
f strings
1. Introduction Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Introduction 
       
       # f strings are available only above python 3.5 ; so if you are suing lower version 
       # than 3.5 then you need install f string separately
       # Here is the Simple Example of fstring
       
       first_name="Mangesh"
       last_name="Pande"
       
       print (f'{first_name} {last_name}')
     
       
2. Running string functions inside fstring Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Running string functions inside fstring 
            
       first_name="Mangesh"
       last_name="Pande"
       
       print (f'{first_name.upper()} {last_name.upper()}')
       
3. Printing Dictionary Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Printing Dictionary 
       
       # Here while printing in f string instead on single quotes we are using double quotes 
       # as dictionary is already having single quotes
       
       my_dict = {'name':'Mangesh Pande', 'age':33, 'gender':'Male'}
       print(f"Hello My Name is {my_dict['name']} , age is {my_dict['age']} , gender is {my_dict['gender']}" )
            
4. Printing Mathematical calclulation output Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Printing Mathematical calclulation output
       
       # We can directly perform math operation in f string   
           
       calclulation = f'4 times 11 is equal to {4 * 11}'
       print(calclulation)
      
5. printing values in for loop using f string Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # printing values in for loop using f string
       
       for n in range(1, 11):
       	sentence = f'The value is {n}'
       	print(sentence)
       
       # Printing numbers by padding with 0s
       # The below code will print 3 digit number padding with first two digits as 0 i.e 001 and 010
       # You can increase or decrease the padding based on your requirement {n:0}
       # If you remove the {n:0} and put any number like 1 ,5 etc.. then that much number of space will be added to your  
       # number
       
       # EX - 2 
       
       for n in range(1, 11):
       	sentence = f'The value is {n:3}'
       	print(sentence)
       
       
6. Printing floating point numbers Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Printing floating point numbers 

       pi = 3.14159925
       # The below print statement just printing floating point value as it is
       sentence = f'Pi is equal to {pi}'
       print(sentence)

       # The below Print statement print folating point number upto 4 decimal digit 
       # sometimes it round off the last digit based on values 
       
       sentence = f'Pi is equal to {pi:.4f}'
       print(sentence)
   
7. Printing dates using date format Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Printing dates using date format 
       # for date formatting we can use Python documentation 
       
       from datetime import datetime
       birthday = datetime(1990, 1, 1)
       sentence = f'Mangesh has a birthday on {birthday:%B, %d, %Y}'
       print(sentence)
        
Untitled Document