1# f-strings are short for formatted string like the following
2# you can use the formatted string by two diffrent ways
3# 1
4name = "John Smith"
5print(f"Hello, {name}") # output = Hello, John Smith
6
7# 2
8name = "John Smith"
9print("Hello, {}".format(name)) # output = Hello, John Smith
10
1# f-string is a format for printing / returning data
2# It helps you to create more consise and elegant code
3
4########### Example program ##############
5
6# User inputs their name (e.g. Michael Reeves)
7name = input()
8# Program welcomes the user
9print(f"Welcome to grepper {name}")
10
11################ Output ################
12
13""" E.g. Welcome to grepper Michael Reeves """
1>>> name = "Eric"
2>>> age = 74
3>>> f"Hello, {name}. You are {age}."
4'Hello, Eric. You are 74.'
5
1num_01, num_02, num_03 = 1, 2, 3
2print(f"Numbers : {num_01}, {num_02}, {num_03}")
3
4"""
5>>> Numbers: 1, 2, 3
6"""
1# f-strings help in string concatenation
2name = 'Psych4_3.8.3'
3age = 23
4job = 'programmer'
5
6#USING OLD METHOD
7print("I am %s a %t of age %u", %(name, job, age))
8
9# USING F-STRING
10print(f"I am {name} a {job} of age {age}")
11# here you can even see whcih value is inserted in which place....
12# the f means that it is an f string. DONT FORGET IT!!
1#takes age as input
2age=input("Enter your age: ")
3#prints the input of age with a formatted string
4print(f'You are {age} years old!')