DEV Community

Saravanan B
Saravanan B

Posted on

#2 Python Series...

Hi....

If we use len function for string it will print the lenth of the string by calculating value. What if we print a length of integer??..
Let's see in compiler...
Image description

If we use Double quote for integer then it is treated as a String....

Image description

To over come this need to understand what is data types.

Interger - (123)
Flaot - (123.321)
String - ("Hello World!")
Boolean - true / false

The variable type can be checked with compiler by using type function.

Type(variable_declartion).
Image description

Type casting- Means converting type

num = len(input("Drop a message"))

new_num_char = str(num)

Image description

Exersise :

String input to int and add the string values.

Image description

Mathamatical Operations:
a = 5
b = 10
sum = a+b
subtract = a-b
multiply = a*b
divide = a/b
power = a ** b

Image description

PEMDAS- priority
()
**
*
/

+

Image description

BMI - Calculator

Excersice:
Image description

Flow division :

print(10//5)
output = 2
without using round or type casting we can achieve int value by using this.

f-String

score = 0

print(f"your score is {0}")
this f string type cast in a quick and easy way.....

Project: Tip calculator.
Image description

GitLink : https://github.com/Saravananb15/Python/tree/day2

Top comments (0)