You are on page 1of 2

Python (FreeCodeCamp.

com)
Expressions
Operators

Data types
Python automatically detects the type of the entered value. With “type(‘XXX’)” Python will return the
type of the evaluated variable or value.
Integer + Integer = Integer
Integer * Integer = Integer
Integer / Integer = Float
Integer + Float = Float

x=1 xx=-50 xf=8.6 xf2=x+xf


print(type(x)) print(type(xx)) print(type(xf)) print(type(xf2))
<class 'int'> <class 'int'> <class 'float'> <class 'float'>

y='a' yy='asdf'
print(type(y)) print(type(yy))
<class 'str'> <class 'str'>

Integer  String conversion


xint=123 xstr=str(xint) xint2=int(xstr)
print(type(xint)) print(type(xstr)) print(type(xint2))
<class 'int'> <class 'str'> <class 'int'>

User input
To read a number from user it must be converted to an integer.
name_user=input('Who are you?\n >\t' ) age_user=int(input('How old are you?\n >\t'))
print('Welcome,', name_user) print('So you were born in',(2021-age_user))

Who are you? How old are you?


> George > 24
Welcome, George So you were born in 1997
Comments
Simply write after ‘#’

You might also like