Python as a Calculator

Python interpreter can be used as a calculator. You can perform arithmetic operations without using variables, functions or classes. Values will be displayed on console without the help of print function.

calculator
  1. Addition
  2. Subtraction
  3. Multiplication
  4. Float Division
  5. Integer Division
  6. Calculate Remainder
  7. Calculate Power
  8. Print Strings etc., Operations can be performed.

Python Syntax is less complex and easy to remember. Let's begin with some ground rules.

Comments in Python

Comments in Python start with the hash character, #, and extend to the end of the physical line. Since comments are to clarify code, they are not interpreted by the Python interpreter.

Python Identifiers

A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter

  1. A to Z or
  2. a to z or
  3. an underscore (_)

followed by zero or more letters, underscores and digits (0 to 9). Python does not allow any operators such as +, -, *, /, //, %  and characters such as @, $, ~ etc. within identifiers.

Basic built-in functions

Every python programmer uses these functions on a regular basis.

  1. help()
  2. input()
  3. print()
  4. id()
  5. type()
  6. del()
  • help()

    It is an interactive help, where you can input any module,class,object,function,method and their usage will be displayed on screen. We can use help() in 2 ways(with 1 argument , or with no argument).

  1. help() - with no arguments passed, displays interactive help, where we can type in required function or module to display related details.Type quit to exit interactive help.
  2. help(arg) - it displays information related to the argument passed.
help() with 0 arguments
help (1)
help(arg) - help with 1 argument. eg:- help(str)
help(str)
  • input()

    input builtin function, is used to take user input during run time. It waits for the user to enter a value. Irrespective of the input given, value returned by this function will always be a string(<str> object). input() function can be used in 2 ways.

  1. input()- without argument.
  2. input(arg)- with argument, then argument gets displayed on console.
  • print() 

    It is used to print values on the console or display values on the screen. From python 3, we can also use 'sep', 'end' parameters(optional).

    Syntax:  print(args,sep=' ',end='\n')

  1. sep:- Space is the default separator between the arguments in print()  function in Python, which can be modified using sep and any character, integer or string can be printed instead.
  2. end:- Python’s print() function comes with a parameter called ‘end’. By default, the value of this  is ‘\n’, i.e. the new line character. You can end a print statement with any character/string using this parameter.
  • id(obj) 

    An object is passed as an argument and an unique integer value associated with that object is returned.

  • type(obj) 

    An object is passed as an argument and the type of that object is returned.

  • del keyword

    It is used to delete objects.