Working with text and numbers in Python


By reading this article your following problems will be answered.

How to manipulate text and numbers in Python.
How to print text and numbers in Python.
How to use Strings in Python.
How to do calculations in Python.
Special operators in Python.

Basic text in Python

  • To print on python,
  • In python a text should always be a “String”, and it should be inside “”.
  • To combine two text strings together, a ‘+’ sign is always required. And the two strings need to be always inside “”.
  • Python does not support ‘&’ when combining two text strings. (Only ‘+’ is valid.)
  • Alternatively a comma also can be used to combine two strings.
  • But when using a comma, it will automatically add a space between those two strings.
  • Adding a space manually before or after any string is not required with comma.

Numbers in Python

  • When we need to display numbers in python, numbers can be interpreted without “” as just numbers.
  • Numbers can be calculated in print function (Using +, -, / & *)
  • Python uses BODMAS to calculate numbers.
  • When combining a text string and a number (Not a string, just a plain number) in python, a comma is always the right thing. In this case adding ‘+’ between a test string and a number (Without “”) gives an error.
  • But if we consider the number as a string by adding “”, ‘+’ will definitely work.

Special operators in Python

  • When // is added between two numbers it rounds down the division to a whole number.
  • Actually, when // is used it gives the largest integer as the output.
  • When % added between two numbers it displays the remainder.
  • The operators // and % works similar to division but they gives different outputs.

Click here to know more about Python