Number and string

Number and string are the basic variables in python.

Number

int and float are the most common number. python can be used as a calculator.

  • Examples
# int a, float b
a = 4
b = 3.4
  • Floor division
a // b

1.0

  • Powers
a ** b

111.43047210190387

  • round() function - return a floating point number that is a rounded of a specified number; “_” - last printed variables
rouond(_, 2)

111.43

String

  • Examples
a = "Py"
b = "thon"
a + b

‘Python’

  • Select sub strings
a[0]

‘P’

b[2:4]

‘on’

  • Length of the string - len()
len(b)

4

  • Convert to string - str()
a = 4304
str(a)

‘4304’