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.
- Float Division
- Integer Division
- Calculate Remainder
- Calculate Power
- 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.
A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter
- A to Z or
- a to z or
- 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.
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).
- 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.
- help(arg) - it displays information related to the argument passed.
help() with 0 arguments
help(arg) - help with 1 argument. eg:- help(str)
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.
- input()- without argument.
- input(arg)- with argument, then argument gets displayed on console.
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')
- 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.
- 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.
An object is passed as an argument and an unique integer value associated with that object is returned.
An object is passed as an argument and the type of that object is returned.
It is used to delete objects.