Python tutorial- numbers and expressions

Numbers and Expressions

Python can be a powerful calculator? The answer is definitely yes. You can make calculations simply.

>>> 2+2



>>> 2*4



>>> 5/3



Note: the division of an integer value and another integer value will round the result to an integer value. To get the result as normal division, the easiest way is to use the real values.

>>> 5.0/3.0




To do a modulus division, you can use % operator.

>>> 3%2




To convert the hexadecimal or octal values to integral value, simply type the hexadecimal or octal values and to convert from hexadecimal, and octal to decimal values, you can use hec(), and oct() methods.

>>> 0xF


>>> 015


>>> hex(10)


>>> oct(10)




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.