Day 7: Type casting in python

Like many languages, python can coerce values of certain types to something else. Unlike javascript, python is bit more strict about type casting.

age = input ("Enter your age: ")
print ("You are " + age + " years old.")

age = int(age)

print ("You will be " + str(float(age + 10)) + " years old in the year " + str(2022 + 10) + ".")

F-Strings

Similar to javascript’s own template literals, Python has its own way of evaluating and formatting strings

age = input ("Enter your age: ")
print ("You are " + age + " years old.")

age = int(age)

print (f"You will be {float(age + 10)} years old in the year {2022 + 10}.")
What’s your Reaction?
+1
0
+1
0
+1
1

Published by Soumil Roy

I'm a Full-Stack Developer with 7+ years of experience in Web design & development .Currently building expertise in React, TypeScript & GraphQL

Leave a comment

Your email address will not be published.

Open WhatApp
Hello 👋 Click the button below connect with me.